From 91260d2f57eb8f18dd717c4b081a46a1423d339a Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 14 Apr 2017 11:22:59 -0700 Subject: [PATCH 01/16] Not used. --- .../kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt | 3 --- 1 file changed, 3 deletions(-) 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 4f42f6c4..f5e21b8d 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt @@ -11,9 +11,7 @@ import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.KFiles import com.google.inject.Inject import java.io.File -import java.io.OutputStream import java.nio.file.Paths -import java.util.jar.JarOutputStream class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger) : ArchiveGenerator { @@ -86,7 +84,6 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, manifest.mainAttributes.putValue(attribute.first, attribute.second) } - val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) } return Archives.generateArchive(project, context, war.name, ".war", files, false /* don't expand jar files */, manifest) } From 2b3fc7a2c966c3c7f12a9aa2324386d775e1813b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 14 Apr 2017 12:14:43 -0700 Subject: [PATCH 02/16] Fix the zip task. --- .../com/beust/kobalt/archive/MetaArchive.kt | 15 ++++++++++----- .../main/kotlin/com/beust/kobalt/misc/JarUtils.kt | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/MetaArchive.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/MetaArchive.kt index 1e531359..69918dd4 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/MetaArchive.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/MetaArchive.kt @@ -3,28 +3,33 @@ package com.beust.kobalt.archive import com.beust.kobalt.Glob import com.beust.kobalt.misc.KFiles import org.apache.commons.compress.archivers.ArchiveEntry +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream import java.io.Closeable import java.io.File import java.io.FileInputStream import java.io.FileOutputStream import java.nio.file.Files +import java.util.jar.Manifest import org.apache.commons.compress.archivers.zip.ZipFile as ApacheZipFile /** * Abstraction of a zip/jar/war archive that automatically manages the addition of expanded jar files. * Uses ZipArchiveOutputStream for fast inclusion of expanded jar files. */ -class MetaArchive(outputFile: File, val manifest: java.util.jar.Manifest?) : Closeable { +class MetaArchive(outputFile: File, val manifest: Manifest?) : Closeable { private val zos = ZipArchiveOutputStream(outputFile).apply { encoding = "UTF-8" } - fun addFile(file: File, path: String) { + fun addFile(f: File, entryFile: File, path: String?) { + val file = f.normalize() FileInputStream(file).use { inputStream -> - val entry = zos.createArchiveEntry(file, path) - maybeAddEntry(entry) { - addEntry(entry, inputStream) + val actualPath = if (path != null) path + entryFile.path else entryFile.path + ZipArchiveEntry(actualPath).let { entry -> + maybeAddEntry(entry) { + addEntry(entry, inputStream) + } } } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt index 81420a43..5d4aa8cd 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt @@ -55,7 +55,10 @@ class JarUtils { kobaltLog(2, " Writing contents of jar file $foundFile") metaArchive.addArchive(foundFile) } else { - metaArchive.addFile(File(directory, fromFile.path), foundFile.path) + val fp = foundFile.path + val toPath = File(file.to).normalize().path + val finalPath = if (toPath.isEmpty()) null else (toPath + "/") + metaArchive.addFile(File(directory, fromFile.path), foundFile, finalPath) } } catch(ex: Exception) { onError(ex) From 19dc26ac16867ade7e0402760a1b7b72d138b0e5 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 14 Apr 2017 12:15:01 -0700 Subject: [PATCH 03/16] Make sure the zip entries start with kobalt-${version}. --- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 03278f4e..18aa4263 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -1,12 +1,19 @@ package com.beust.kobalt -import com.beust.kobalt.misc.* +import com.beust.kobalt.misc.KFiles +import com.beust.kobalt.misc.kobaltLog +import com.beust.kobalt.misc.warn import org.testng.annotations.Test -import java.io.* +import java.io.File +import java.io.FileInputStream +import java.io.FileReader +import java.io.InputStream import java.nio.file.Files import java.nio.file.Paths import java.util.* -import java.util.jar.* +import java.util.jar.JarEntry +import java.util.jar.JarFile +import java.util.jar.JarInputStream /** * Make sure the distribution zip file contains all the right files and no bad files. @@ -23,13 +30,17 @@ class VerifyKobaltZipTest : KobaltTest() { var foundJar = false var foundWrapperJar = false - val mainJarFilePath = "kobalt-$KOBALT_VERSION.jar" - val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "kobalt-$KOBALT_VERSION.zip") + val root = "kobalt-$KOBALT_VERSION" + val mainJarFilePath = "$root.jar" + val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "$root.zip") if (File(zipFilePath).exists()) { val zipFile = JarFile(zipFilePath) val stream = JarInputStream(FileInputStream(zipFilePath)) var entry = stream.nextEntry while (entry != null) { + if (! entry.name.startsWith(root)) { + throw AssertionError("Entries in the zip file should be under the directory $root") + } if (entry.name.endsWith("kobaltw")) { val ins = zipFile.getInputStream(entry) ins.readBytes().forEach { From f4a5d188e7cef7b3a97bd3f6c384955b328eba09 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 14 Apr 2017 12:15:50 -0700 Subject: [PATCH 04/16] Use AssertionErrors in tests. --- .../kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 18aa4263..c15e95d2 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -46,19 +46,19 @@ class VerifyKobaltZipTest : KobaltTest() { ins.readBytes().forEach { // Look for carriage returns if (it.compareTo(13) == 0) { - throw KobaltException("kobaltw has wrong line endings") + throw AssertionError("kobaltw has wrong line endings") } } if (OperatingSystem.current().isWindows()) { warn("Can't determine if kobaltw is executable under Windows") } else if (!Files.isExecutable(Paths.get("dist/kobaltw"))) { - throw KobaltException("kobaltw has invalid permissions") + throw AssertionError("kobaltw has invalid permissions") } foundKobaltw = true } else if (entry.name.endsWith(mainJarFilePath)) { val ins = zipFile.getInputStream(entry) if (ins.available() < 20000000) { - throw KobaltException(mainJarFilePath + " is too small: " + mainJarFilePath) + throw AssertionError(mainJarFilePath + " is too small: " + mainJarFilePath) } verifyMainJarFile(ins) foundJar = true @@ -70,13 +70,13 @@ class VerifyKobaltZipTest : KobaltTest() { entry = stream.nextEntry } if (!foundKobaltw) { - throw KobaltException("Couldn't find kobaltw in $zipFilePath") + throw AssertionError("Couldn't find kobaltw in $zipFilePath") } if (!foundJar) { - throw KobaltException("Couldn't find jar in $zipFilePath") + throw AssertionError("Couldn't find jar in $zipFilePath") } if (!foundWrapperJar) { - throw KobaltException("Couldn't find wrapper jar in $zipFilePath") + throw AssertionError("Couldn't find wrapper jar in $zipFilePath") } kobaltLog(1, "$zipFilePath looks correct") } else { From c4813880acb16e0cd13b280051a83c6c800594e1 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 14 Apr 2017 12:15:55 -0700 Subject: [PATCH 05/16] Comment. --- kobalt/src/Build.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index f335067c..a497aac2 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -223,6 +223,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { include(from(files[i]), to(files[i + 1]), files[i + 2]) } + // Package the sources val currentDir = Paths.get(".").toAbsolutePath().normalize().toString() zipFolders("$currentDir/$buildDirectory/libs/all-sources/$projectName-$version-sources.jar", "$currentDir/$directory/src/main/kotlin", From e45e93cee88f15209e9631591dd8abcf7c763ef7 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 14 Apr 2017 12:24:27 -0700 Subject: [PATCH 06/16] 1.0.62. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index db96a9e1..f5e39865 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.61 +kobalt.version=1.0.62 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index db96a9e1..f5e39865 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.61 +kobalt.version=1.0.62 From 876420b434d6f947b0e108730f86321cc062ff9a Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 14 Apr 2017 22:45:37 -0700 Subject: [PATCH 07/16] Fix for OSX and calling outsite of residing directory. --- dist/kobaltw | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dist/kobaltw b/dist/kobaltw index 4f39dc35..333738df 100755 --- a/dist/kobaltw +++ b/dist/kobaltw @@ -1,7 +1,11 @@ #!/usr/bin/env sh -DIRNAME=`dirname $(readlink -f "$0")` -if [[ "$(uname)" == "CYGWIN"* ]]; then - DIRNAME=`cygpath -d "$DIRNAME"` +case "$(uname)" in + CYGWIN*) DIRNAME=$(cygpath -d "$(dirname "$(readlink -f "$0")")");; + Darwin*) DIRNAME=$(dirname "$(readlink "$0")");; + *) DIRNAME=$(dirname "$(readlink -f "$0")");; +esac +if [ "$DIRNAME" = "." ]; then + DIRNAME="$(dirname "$0")" fi java -jar "${DIRNAME}/../kobalt/wrapper/kobalt-wrapper.jar" $* \ No newline at end of file From 1fb984ff63e58c696df63ae36e594f34d03cefb9 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 15 Apr 2017 07:49:35 -0700 Subject: [PATCH 08/16] 1.0.63. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index f5e39865..e23fe5ec 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.62 +kobalt.version=1.0.63 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index f5e39865..e23fe5ec 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.62 +kobalt.version=1.0.63 From 85460422e0797f266b4d4b88330d5606be608646 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 15 Apr 2017 07:51:44 -0700 Subject: [PATCH 09/16] GH-414: Authenticated repos not working. Fixes https://github.com/cbeust/kobalt/issues/414 --- .../kotlin/com/beust/kobalt/api/Kobalt.kt | 4 ++ .../kotlin/com/beust/kobalt/maven/Kurl.kt | 25 +---------- .../maven/aether/KobaltMavenResolver.kt | 42 ++++++++++++++++++- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt index 527d35b2..f825efeb 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt @@ -5,6 +5,7 @@ import com.beust.kobalt.HostConfig import com.beust.kobalt.Plugins import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.maven.DependencyManager +import com.beust.kobalt.maven.aether.KobaltMavenResolver import com.google.inject.Guice import com.google.inject.Injector import com.google.inject.Module @@ -55,6 +56,9 @@ class Kobalt { // Repos from the build file result.addAll(reposFromBuildFiles) + result.forEach { + KobaltMavenResolver.initAuthentication(it) + } return result.toHashSet() } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Kurl.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Kurl.kt index 6b9c0a62..909c18c5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Kurl.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Kurl.kt @@ -1,9 +1,8 @@ package com.beust.kobalt.maven import com.beust.kobalt.HostConfig -import com.beust.kobalt.KobaltException +import com.beust.kobalt.maven.aether.KobaltMavenResolver import com.beust.kobalt.maven.dependency.FileDependency -import com.beust.kobalt.misc.LocalProperties import java.io.* import java.net.HttpURLConnection import java.net.URL @@ -21,27 +20,7 @@ class Kurl(val hostInfo: HostConfig) { } init { - // See if the URL needs to be authenticated. Look in local.properties for keys - // of the format authUrl..user=xxx and authUrl..password=xxx - val properties = LocalProperties().localProperties - val host = java.net.URL(hostInfo.url).host - properties.entries.forEach { - val key = it.key.toString() - if (key == "$KEY.$host.$VALUE_USER") { - hostInfo.username = properties.getProperty(key) - } else if (key == "$KEY.$host.$VALUE_PASSWORD") { - hostInfo.password = properties.getProperty(key) - } - } - fun error(s1: String, s2: String) { - throw KobaltException("Found \"$s1\" but not \"$s2\" in local.properties for $KEY.$host", - docUrl = "http://beust.com/kobalt/documentation/index.html#maven-repos-authenticated") - } - if (! hostInfo.username.isNullOrBlank() && hostInfo.password.isNullOrBlank()) { - error("username", "password") - } else if(hostInfo.username.isNullOrBlank() && ! hostInfo.password.isNullOrBlank()) { - error("password", "username") - } + KobaltMavenResolver.initAuthentication(hostInfo) } override fun toString() = hostInfo.toString() diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt index 376081df..18ed6659 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt @@ -2,11 +2,14 @@ package com.beust.kobalt.maven.aether import com.beust.kobalt.Args import com.beust.kobalt.HostConfig +import com.beust.kobalt.KobaltException import com.beust.kobalt.api.Kobalt import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.getProxy +import com.beust.kobalt.maven.Kurl import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.maven.MavenId +import com.beust.kobalt.misc.LocalProperties import com.google.common.eventbus.EventBus import com.google.inject.Inject import org.eclipse.aether.artifact.Artifact @@ -21,6 +24,7 @@ import org.eclipse.aether.resolution.DependencyRequest import org.eclipse.aether.resolution.DependencyResult import org.eclipse.aether.resolution.VersionRangeRequest import org.eclipse.aether.resolution.VersionRangeResult +import org.eclipse.aether.util.repository.AuthenticationBuilder import java.util.* class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, @@ -32,6 +36,31 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, MavenId.toId(it.groupId, it.artifactId, it.extension, it.classifier, it.version) } fun isRangeVersion(id: String) = id.contains(",") + + fun initAuthentication(hostInfo: HostConfig) { + // See if the URL needs to be authenticated. Look in local.properties for keys + // of the format authUrl..user=xxx and authUrl..password=xxx + val properties = LocalProperties().localProperties + val host = java.net.URL(hostInfo.url).host + properties.entries.forEach { + val key = it.key.toString() + if (key == "${Kurl.KEY}.$host.${Kurl.VALUE_USER}") { + hostInfo.username = properties.getProperty(key) + } else if (key == "${Kurl.KEY}.$host.${Kurl.VALUE_PASSWORD}") { + hostInfo.password = properties.getProperty(key) + } + } + fun error(s1: String, s2: String) { + throw KobaltException("Found \"$s1\" but not \"$s2\" in local.properties for ${Kurl.KEY}.$host", + docUrl = "http://beust.com/kobalt/documentation/index.html#maven-repos-authenticated") + } + if (! hostInfo.username.isNullOrBlank() && hostInfo.password.isNullOrBlank()) { + error("username", "password") + } else if(hostInfo.username.isNullOrBlank() && ! hostInfo.password.isNullOrBlank()) { + error("password", "username") + } + + } } fun resolveToArtifact(id: String, scope: Scope? = null, @@ -110,8 +139,17 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, private val system = Booter.newRepositorySystem() private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus) - private fun createRepo(hostConfig: HostConfig) = - RemoteRepository.Builder(hostConfig.name, "default", hostConfig.url).build() + private fun createRepo(hostConfig: HostConfig) : RemoteRepository { + val builder = RemoteRepository.Builder(hostConfig.name, "default", hostConfig.url) + if (hostConfig.hasAuth()) { + val auth = AuthenticationBuilder() + .addUsername(hostConfig.username) + .addPassword(hostConfig.password) + .build() + builder.setAuthentication(auth) + } + return builder.build() + } private val kobaltRepositories: List get() = Kobalt.repos.map { From 30e71afbc8a8e09d523c949968d75b799e0e81f8 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 15 Apr 2017 07:52:02 -0700 Subject: [PATCH 10/16] 1.0.64. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index e23fe5ec..36041074 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.63 +kobalt.version=1.0.64 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index e23fe5ec..36041074 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.63 +kobalt.version=1.0.64 From 822a9701a6c9f228cfc70b225738c4d426266908 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 16 Apr 2017 18:24:26 -0700 Subject: [PATCH 11/16] Fix broken TestNG dependency. --- kobalt/src/Build.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index a497aac2..76c1a7af 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -114,7 +114,7 @@ val kobaltPluginApi = project { "org.slf4j:slf4j-simple:${Versions.slf4j}", *mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"), "org.apache.maven:maven-aether-provider:3.3.9", - "org.testng.testng-remote:testng-remote:1.3.0", + "org.testng.testng-remote:testng-remote:1.3.2", "org.testng:testng:${Versions.testng}", "commons-io:commons-io:2.5", "org.junit.platform:junit-platform-surefire-provider:${Versions.junitPlatform}", From 4f9c5f383ed801b611b0cc87f194e010b0fcb5ef Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 16 Apr 2017 18:53:01 -0700 Subject: [PATCH 12/16] 1.0.65. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index 36041074..bd5e50a2 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.64 +kobalt.version=1.0.65 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 36041074..bd5e50a2 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.64 +kobalt.version=1.0.65 From cbb02e76150f4241d73f9471e2d5a9c4bf236c08 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 16 Apr 2017 19:08:22 -0700 Subject: [PATCH 13/16] 1.0.66. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index bd5e50a2..c5750f12 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.65 +kobalt.version=1.0.66 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index bd5e50a2..c5750f12 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.65 +kobalt.version=1.0.66 From a7006d5cd77cf2c7772305813ae340d2ba3c3e44 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 16 Apr 2017 19:21:50 -0700 Subject: [PATCH 14/16] kapt3 work. --- .../com/beust/kobalt/plugin/apt/AptPlugin.kt | 119 +++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index b90c9f5a..039e22be 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -1,10 +1,19 @@ package com.beust.kobalt.plugin.apt +import com.beust.kobalt.Constants +import com.beust.kobalt.TaskResult import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive +import com.beust.kobalt.api.annotation.Task +import com.beust.kobalt.homeDir +import com.beust.kobalt.internal.CompilerUtils import com.beust.kobalt.maven.DependencyManager +import com.beust.kobalt.maven.aether.Filters +import com.beust.kobalt.maven.aether.Scope +import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.warn +import com.beust.kobalt.plugin.kotlin.KotlinPlugin import com.google.common.collect.ArrayListMultimap import com.google.inject.Inject import java.io.File @@ -19,7 +28,8 @@ import javax.inject.Singleton * (outputDir, etc...). */ @Singleton -class AptPlugin @Inject constructor(val dependencyManager: DependencyManager) +class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, val kotlinPlugin: KotlinPlugin, + val compilerUtils: CompilerUtils) : BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor { // ISourceDirectoryContributor @@ -49,6 +59,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager) override val name = PLUGIN_NAME override fun apply(project: Project, context: KobaltContext) { + super.apply(project, context) listOf(aptConfigs[project.name]?.outputDir, aptConfigs[project.name]?.outputDir) .filterNotNull() .distinct() @@ -66,6 +77,110 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager) KFiles.joinAndMakeDir(project.directory, project.buildDirectory, outputDir, context.variant.toIntermediateDir()) + private fun generatedSources(project: Project, context: KobaltContext, outputDir: String) = + KFiles.joinDir(generated(project, context, outputDir), "sources") + private fun generatedStubs(project: Project, context: KobaltContext, outputDir: String) = + KFiles.joinDir(generated(project, context, outputDir), "stubs") + private fun generatedClasses(project: Project, context: KobaltContext, outputDir: String) = + KFiles.joinDir(generated(project, context, outputDir), "classes") + +// @Task(name = "compileKapt", dependsOn = arrayOf("runKapt"), reverseDependsOn = arrayOf("compile")) + fun taskCompileKapt(project: Project) : TaskResult { + kaptConfigs[project.name]?.let { config -> + val sourceDirs = listOf( + generatedStubs(project, context, config.outputDir), + generatedSources(project, context, config.outputDir)) + val sourceFiles = KFiles.findSourceFiles(project.directory, sourceDirs, listOf("kt", "java")).toList() + val buildDirectory = File(KFiles.joinDir(project.directory, + generatedClasses(project, context, config.outputDir))) + val flags = listOf() + val cai = CompilerActionInfo(project.directory, allDependencies(), sourceFiles, listOf(".kt"), + buildDirectory, flags, emptyList(), forceRecompile = true) + + val cr = compilerUtils.invokeCompiler(project, context, kotlinPlugin.compiler, cai) + println("") + } + + return TaskResult() + } + + val annotationDependencyId = "org.jetbrains.kotlin:kotlin-annotation-processing:" + + Constants.KOTLIN_COMPILER_VERSION + + fun annotationProcessorDependency() = dependencyManager.create(annotationDependencyId) + + fun aptJarDependencies() : List { + val apDep = dependencyManager.create("net.thauvin.erik.:semver:0.9.6-beta") + val apDep2 = FileDependency(homeDir("t/semver-example-kotlin/lib/semver-0.9.7.jar")) + return listOf(apDep2) + } + + fun allDependencies(): List { + val allDeps = listOf(annotationProcessorDependency()) + aptJarDependencies() + + return allDeps + } + +// @Task(name = "runKapt", reverseDependsOn = arrayOf("compile"), runAfter = arrayOf("clean")) + fun taskRunKapt(project: Project) : TaskResult { + val flags = arrayListOf() + kaptConfigs[project.name]?.let { config -> + + fun kaptPluginFlag(flagValue: String): String { + return "plugin:org.jetbrains.kotlin.kapt3:$flagValue" + } + + val generated = generated(project, context, config.outputDir) + val generatedSources = generatedSources(project, context, config.outputDir) + File(generatedSources).mkdirs() + + val allDeps = allDependencies() + flags.add("-Xplugin") + flags.add(annotationProcessorDependency().jarFile.get().absolutePath) + flags.add("-P") + val kaptPluginFlags = arrayListOf() +// kaptPluginFlags.add(kaptPluginFlag("aptOnly=true")) + + kaptPluginFlags.add(kaptPluginFlag("sources=" + generatedSources)) + kaptPluginFlags.add(kaptPluginFlag("classes=" + generatedClasses(project, context, config.outputDir))) + kaptPluginFlags.add(kaptPluginFlag("stubs=" + generatedStubs(project, context, config.outputDir))) + kaptPluginFlags.add(kaptPluginFlag("verbose=true")) + kaptPluginFlags.add(kaptPluginFlag("aptOnly=false")) + val dependencies = dependencyManager.calculateDependencies(project, context, + Filters.EXCLUDE_OPTIONAL_FILTER, + listOf(Scope.COMPILE), + allDeps) + dependencies.forEach { + val jarFile = it.jarFile.get() + kaptPluginFlags.add(kaptPluginFlag("apclasspath=$jarFile")) + } + + flags.add(kaptPluginFlags.joinToString(",")) + listOf("-language-version", "1.1", " -api-version", "1.1").forEach { + flags.add(it) + } + val sourceFiles = +// KFiles.findSourceFiles(project.directory, +// listOf("src/tmp/kotlin"), +// listOf("kt")) +// .toList() + + KFiles.findSourceFiles(project.directory, project.sourceDirectories, listOf("kt")).toList() + + generatedSources +// + val buildDirectory = File(KFiles.joinDir(project.directory, generated)) + val cai = CompilerActionInfo(project.directory, allDeps, sourceFiles, listOf(".kt"), + buildDirectory, flags, emptyList(), forceRecompile = true) + + println("FLAGS: " + flags.joinToString("\n")) + println(" " + kaptPluginFlags.joinToString("\n ")) + val cr = compilerUtils.invokeCompiler(project, context, kotlinPlugin.compiler, cai) + println("") + } + + return TaskResult() + } + // ICompilerFlagContributor override fun compilerFlagsFor(project: Project, context: KobaltContext, currentFlags: List, suffixesBeingCompiled: List): List { @@ -76,7 +191,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager) fun addFlags(outputDir: String) { aptDependencies[project.name]?.let { result.add("-s") - result.add(generated(project, context, outputDir)) + result.add(generatedSources(project, context, outputDir)) } } From 6816ba8a3bc82e5909d983cd16dffeeeccda2ea7 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 16 Apr 2017 20:13:28 -0700 Subject: [PATCH 15/16] Sanitize repo names from repos(). --- .../src/main/kotlin/com/beust/kobalt/BuildScript.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt index 48ecc0e3..799964bf 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt @@ -74,7 +74,7 @@ data class ProxyConfig(val host: String = "", val port: Int = 0, val type: Strin fun toAetherProxy() = Proxy(type, host, port) // TODO make support for proxy auth } -data class HostConfig(var url: String = "", var name: String = url, var username: String? = null, +data class HostConfig(var url: String = "", var name: String, var username: String? = null, var password: String? = null) { fun hasAuth() : Boolean { return (! username.isNullOrBlank()) && (! password.isNullOrBlank()) @@ -95,8 +95,10 @@ fun repos(vararg repos : String) { newRepos(*repos) } +fun createRepoName(url: String) = url.replace("/", "_").replace("\\", "_").replace(":", "_") + fun newRepos(vararg repos: String) { - repos.forEach { Kobalt.addRepo(HostConfig(it)) } + repos.forEach { Kobalt.addRepo(HostConfig(it, createRepoName(it))) } } fun buildFileClasspath(vararg deps: String) { @@ -115,7 +117,7 @@ fun authRepos(vararg repos : HostConfig) { } @Directive -fun authRepo(init: HostConfig.() -> Unit) = HostConfig().apply { init() } +fun authRepo(init: HostConfig.() -> Unit) = HostConfig(name = "").apply { init() } @Directive fun glob(g: String) : IFileSpec.GlobSpec = IFileSpec.GlobSpec(g) From e9b8212dbdddc9a50221ca1b1e7bbfef13df6c78 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 16 Apr 2017 20:30:44 -0700 Subject: [PATCH 16/16] Fix build. --- .../kotlin/com/beust/kobalt/BuildScript.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt index 799964bf..a6db65b3 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt @@ -74,8 +74,18 @@ data class ProxyConfig(val host: String = "", val port: Int = 0, val type: Strin fun toAetherProxy() = Proxy(type, host, port) // TODO make support for proxy auth } -data class HostConfig(var url: String = "", var name: String, var username: String? = null, - var password: String? = null) { +data class HostConfig(var url: String = "", var name: String = HostConfig.createRepoName(url), + var username: String? = null, var password: String? = null) { + + companion object { + /** + * For repos specified in the build file (repos()) that don't have an associated unique name, + * create such a name from the URL. This is a requirement from Maven Resolver, and failing to do + * this leads to very weird resolution errors. + */ + private fun createRepoName(url: String) = url.replace("/", "_").replace("\\", "_").replace(":", "_") + } + fun hasAuth() : Boolean { return (! username.isNullOrBlank()) && (! password.isNullOrBlank()) } @@ -95,10 +105,8 @@ fun repos(vararg repos : String) { newRepos(*repos) } -fun createRepoName(url: String) = url.replace("/", "_").replace("\\", "_").replace(":", "_") - fun newRepos(vararg repos: String) { - repos.forEach { Kobalt.addRepo(HostConfig(it, createRepoName(it))) } + repos.forEach { Kobalt.addRepo(HostConfig(it)) } } fun buildFileClasspath(vararg deps: String) {