1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00
This commit is contained in:
Dmitry Zhuravlev 2017-04-17 11:49:15 +03:00
commit 6d46ba2d0e
13 changed files with 223 additions and 56 deletions

10
dist/kobaltw vendored
View file

@ -1,7 +1,11 @@
#!/usr/bin/env sh #!/usr/bin/env sh
DIRNAME=`dirname $(readlink -f "$0")` case "$(uname)" in
if [[ "$(uname)" == "CYGWIN"* ]]; then CYGWIN*) DIRNAME=$(cygpath -d "$(dirname "$(readlink -f "$0")")");;
DIRNAME=`cygpath -d "$DIRNAME"` Darwin*) DIRNAME=$(dirname "$(readlink "$0")");;
*) DIRNAME=$(dirname "$(readlink -f "$0")");;
esac
if [ "$DIRNAME" = "." ]; then
DIRNAME="$(dirname "$0")"
fi fi
java -jar "${DIRNAME}/../kobalt/wrapper/kobalt-wrapper.jar" $* java -jar "${DIRNAME}/../kobalt/wrapper/kobalt-wrapper.jar" $*

View file

@ -114,7 +114,7 @@ val kobaltPluginApi = project {
"org.slf4j:slf4j-simple:${Versions.slf4j}", "org.slf4j:slf4j-simple:${Versions.slf4j}",
*mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"), *mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"),
"org.apache.maven:maven-aether-provider:3.3.9", "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}", "org.testng:testng:${Versions.testng}",
"commons-io:commons-io:2.5", "commons-io:commons-io:2.5",
"org.junit.platform:junit-platform-surefire-provider:${Versions.junitPlatform}", "org.junit.platform:junit-platform-surefire-provider:${Versions.junitPlatform}",
@ -223,6 +223,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
include(from(files[i]), to(files[i + 1]), files[i + 2]) include(from(files[i]), to(files[i + 1]), files[i + 2])
} }
// Package the sources
val currentDir = Paths.get(".").toAbsolutePath().normalize().toString() val currentDir = Paths.get(".").toAbsolutePath().normalize().toString()
zipFolders("$currentDir/$buildDirectory/libs/all-sources/$projectName-$version-sources.jar", zipFolders("$currentDir/$buildDirectory/libs/all-sources/$projectName-$version-sources.jar",
"$currentDir/$directory/src/main/kotlin", "$currentDir/$directory/src/main/kotlin",

View file

@ -1 +1 @@
kobalt.version=1.0.61 kobalt.version=1.0.66

View file

@ -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 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 = HostConfig.createRepoName(url),
var password: String? = null) { 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 { fun hasAuth() : Boolean {
return (! username.isNullOrBlank()) && (! password.isNullOrBlank()) return (! username.isNullOrBlank()) && (! password.isNullOrBlank())
} }
@ -115,7 +125,7 @@ fun authRepos(vararg repos : HostConfig) {
} }
@Directive @Directive
fun authRepo(init: HostConfig.() -> Unit) = HostConfig().apply { init() } fun authRepo(init: HostConfig.() -> Unit) = HostConfig(name = "").apply { init() }
@Directive @Directive
fun glob(g: String) : IFileSpec.GlobSpec = IFileSpec.GlobSpec(g) fun glob(g: String) : IFileSpec.GlobSpec = IFileSpec.GlobSpec(g)

View file

@ -5,6 +5,7 @@ import com.beust.kobalt.HostConfig
import com.beust.kobalt.Plugins import com.beust.kobalt.Plugins
import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.aether.KobaltMavenResolver
import com.google.inject.Guice import com.google.inject.Guice
import com.google.inject.Injector import com.google.inject.Injector
import com.google.inject.Module import com.google.inject.Module
@ -55,6 +56,9 @@ class Kobalt {
// Repos from the build file // Repos from the build file
result.addAll(reposFromBuildFiles) result.addAll(reposFromBuildFiles)
result.forEach {
KobaltMavenResolver.initAuthentication(it)
}
return result.toHashSet() return result.toHashSet()
} }

View file

@ -3,28 +3,33 @@ package com.beust.kobalt.archive
import com.beust.kobalt.Glob import com.beust.kobalt.Glob
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import org.apache.commons.compress.archivers.ArchiveEntry import org.apache.commons.compress.archivers.ArchiveEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
import java.io.Closeable import java.io.Closeable
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.FileOutputStream import java.io.FileOutputStream
import java.nio.file.Files import java.nio.file.Files
import java.util.jar.Manifest
import org.apache.commons.compress.archivers.zip.ZipFile as ApacheZipFile 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. * 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. * 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 { private val zos = ZipArchiveOutputStream(outputFile).apply {
encoding = "UTF-8" 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 -> FileInputStream(file).use { inputStream ->
val entry = zos.createArchiveEntry(file, path) val actualPath = if (path != null) path + entryFile.path else entryFile.path
maybeAddEntry(entry) { ZipArchiveEntry(actualPath).let { entry ->
addEntry(entry, inputStream) maybeAddEntry(entry) {
addEntry(entry, inputStream)
}
} }
} }
} }

View file

@ -1,9 +1,8 @@
package com.beust.kobalt.maven package com.beust.kobalt.maven
import com.beust.kobalt.HostConfig 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.maven.dependency.FileDependency
import com.beust.kobalt.misc.LocalProperties
import java.io.* import java.io.*
import java.net.HttpURLConnection import java.net.HttpURLConnection
import java.net.URL import java.net.URL
@ -21,27 +20,7 @@ class Kurl(val hostInfo: HostConfig) {
} }
init { init {
// See if the URL needs to be authenticated. Look in local.properties for keys KobaltMavenResolver.initAuthentication(hostInfo)
// of the format authUrl.<host>.user=xxx and authUrl.<host>.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")
}
} }
override fun toString() = hostInfo.toString() override fun toString() = hostInfo.toString()

View file

@ -2,11 +2,14 @@ package com.beust.kobalt.maven.aether
import com.beust.kobalt.Args import com.beust.kobalt.Args
import com.beust.kobalt.HostConfig import com.beust.kobalt.HostConfig
import com.beust.kobalt.KobaltException
import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.internal.getProxy import com.beust.kobalt.internal.getProxy
import com.beust.kobalt.maven.Kurl
import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.MavenId import com.beust.kobalt.maven.MavenId
import com.beust.kobalt.misc.LocalProperties
import com.google.common.eventbus.EventBus import com.google.common.eventbus.EventBus
import com.google.inject.Inject import com.google.inject.Inject
import org.eclipse.aether.artifact.Artifact 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.DependencyResult
import org.eclipse.aether.resolution.VersionRangeRequest import org.eclipse.aether.resolution.VersionRangeRequest
import org.eclipse.aether.resolution.VersionRangeResult import org.eclipse.aether.resolution.VersionRangeResult
import org.eclipse.aether.util.repository.AuthenticationBuilder
import java.util.* import java.util.*
class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, 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) MavenId.toId(it.groupId, it.artifactId, it.extension, it.classifier, it.version)
} }
fun isRangeVersion(id: String) = id.contains(",") 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.<host>.user=xxx and authUrl.<host>.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, 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 system = Booter.newRepositorySystem()
private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus) private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus)
private fun createRepo(hostConfig: HostConfig) = private fun createRepo(hostConfig: HostConfig) : RemoteRepository {
RemoteRepository.Builder(hostConfig.name, "default", hostConfig.url).build() 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<RemoteRepository> private val kobaltRepositories: List<RemoteRepository>
get() = Kobalt.repos.map { get() = Kobalt.repos.map {

View file

@ -55,7 +55,10 @@ class JarUtils {
kobaltLog(2, " Writing contents of jar file $foundFile") kobaltLog(2, " Writing contents of jar file $foundFile")
metaArchive.addArchive(foundFile) metaArchive.addArchive(foundFile)
} else { } 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) { } catch(ex: Exception) {
onError(ex) onError(ex)

View file

@ -1,10 +1,19 @@
package com.beust.kobalt.plugin.apt 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.*
import com.beust.kobalt.api.annotation.Directive 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.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.KFiles
import com.beust.kobalt.misc.warn import com.beust.kobalt.misc.warn
import com.beust.kobalt.plugin.kotlin.KotlinPlugin
import com.google.common.collect.ArrayListMultimap import com.google.common.collect.ArrayListMultimap
import com.google.inject.Inject import com.google.inject.Inject
import java.io.File import java.io.File
@ -19,7 +28,8 @@ import javax.inject.Singleton
* (outputDir, etc...). * (outputDir, etc...).
*/ */
@Singleton @Singleton
class AptPlugin @Inject constructor(val dependencyManager: DependencyManager) class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, val kotlinPlugin: KotlinPlugin,
val compilerUtils: CompilerUtils)
: BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor { : BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor {
// ISourceDirectoryContributor // ISourceDirectoryContributor
@ -49,6 +59,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager)
override val name = PLUGIN_NAME override val name = PLUGIN_NAME
override fun apply(project: Project, context: KobaltContext) { override fun apply(project: Project, context: KobaltContext) {
super.apply(project, context)
listOf(aptConfigs[project.name]?.outputDir, aptConfigs[project.name]?.outputDir) listOf(aptConfigs[project.name]?.outputDir, aptConfigs[project.name]?.outputDir)
.filterNotNull() .filterNotNull()
.distinct() .distinct()
@ -66,6 +77,110 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager)
KFiles.joinAndMakeDir(project.directory, project.buildDirectory, outputDir, KFiles.joinAndMakeDir(project.directory, project.buildDirectory, outputDir,
context.variant.toIntermediateDir()) 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<String>()
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<IClasspathDependency> {
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<IClasspathDependency> {
val allDeps = listOf(annotationProcessorDependency()) + aptJarDependencies()
return allDeps
}
// @Task(name = "runKapt", reverseDependsOn = arrayOf("compile"), runAfter = arrayOf("clean"))
fun taskRunKapt(project: Project) : TaskResult {
val flags = arrayListOf<String>()
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<String>()
// 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 // ICompilerFlagContributor
override fun compilerFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>, override fun compilerFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
suffixesBeingCompiled: List<String>): List<String> { suffixesBeingCompiled: List<String>): List<String> {
@ -76,7 +191,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager)
fun addFlags(outputDir: String) { fun addFlags(outputDir: String) {
aptDependencies[project.name]?.let { aptDependencies[project.name]?.let {
result.add("-s") result.add("-s")
result.add(generated(project, context, outputDir)) result.add(generatedSources(project, context, outputDir))
} }
} }

View file

@ -11,9 +11,7 @@ import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.google.inject.Inject import com.google.inject.Inject
import java.io.File import java.io.File
import java.io.OutputStream
import java.nio.file.Paths import java.nio.file.Paths
import java.util.jar.JarOutputStream
class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger) class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger)
: ArchiveGenerator { : ArchiveGenerator {
@ -86,7 +84,6 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager,
manifest.mainAttributes.putValue(attribute.first, attribute.second) manifest.mainAttributes.putValue(attribute.first, attribute.second)
} }
val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) }
return Archives.generateArchive(project, context, war.name, ".war", files, return Archives.generateArchive(project, context, war.name, ".war", files,
false /* don't expand jar files */, manifest) false /* don't expand jar files */, manifest)
} }

View file

@ -1 +1 @@
kobalt.version=1.0.61 kobalt.version=1.0.66

View file

@ -1,12 +1,19 @@
package com.beust.kobalt 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 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.Files
import java.nio.file.Paths import java.nio.file.Paths
import java.util.* 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. * Make sure the distribution zip file contains all the right files and no bad files.
@ -23,31 +30,35 @@ class VerifyKobaltZipTest : KobaltTest() {
var foundJar = false var foundJar = false
var foundWrapperJar = false var foundWrapperJar = false
val mainJarFilePath = "kobalt-$KOBALT_VERSION.jar" val root = "kobalt-$KOBALT_VERSION"
val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "kobalt-$KOBALT_VERSION.zip") val mainJarFilePath = "$root.jar"
val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "$root.zip")
if (File(zipFilePath).exists()) { if (File(zipFilePath).exists()) {
val zipFile = JarFile(zipFilePath) val zipFile = JarFile(zipFilePath)
val stream = JarInputStream(FileInputStream(zipFilePath)) val stream = JarInputStream(FileInputStream(zipFilePath))
var entry = stream.nextEntry var entry = stream.nextEntry
while (entry != null) { 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")) { if (entry.name.endsWith("kobaltw")) {
val ins = zipFile.getInputStream(entry) val ins = zipFile.getInputStream(entry)
ins.readBytes().forEach { ins.readBytes().forEach {
// Look for carriage returns // Look for carriage returns
if (it.compareTo(13) == 0) { if (it.compareTo(13) == 0) {
throw KobaltException("kobaltw has wrong line endings") throw AssertionError("kobaltw has wrong line endings")
} }
} }
if (OperatingSystem.current().isWindows()) { if (OperatingSystem.current().isWindows()) {
warn("Can't determine if kobaltw is executable under Windows") warn("Can't determine if kobaltw is executable under Windows")
} else if (!Files.isExecutable(Paths.get("dist/kobaltw"))) { } else if (!Files.isExecutable(Paths.get("dist/kobaltw"))) {
throw KobaltException("kobaltw has invalid permissions") throw AssertionError("kobaltw has invalid permissions")
} }
foundKobaltw = true foundKobaltw = true
} else if (entry.name.endsWith(mainJarFilePath)) { } else if (entry.name.endsWith(mainJarFilePath)) {
val ins = zipFile.getInputStream(entry) val ins = zipFile.getInputStream(entry)
if (ins.available() < 20000000) { if (ins.available() < 20000000) {
throw KobaltException(mainJarFilePath + " is too small: " + mainJarFilePath) throw AssertionError(mainJarFilePath + " is too small: " + mainJarFilePath)
} }
verifyMainJarFile(ins) verifyMainJarFile(ins)
foundJar = true foundJar = true
@ -59,13 +70,13 @@ class VerifyKobaltZipTest : KobaltTest() {
entry = stream.nextEntry entry = stream.nextEntry
} }
if (!foundKobaltw) { if (!foundKobaltw) {
throw KobaltException("Couldn't find kobaltw in $zipFilePath") throw AssertionError("Couldn't find kobaltw in $zipFilePath")
} }
if (!foundJar) { if (!foundJar) {
throw KobaltException("Couldn't find jar in $zipFilePath") throw AssertionError("Couldn't find jar in $zipFilePath")
} }
if (!foundWrapperJar) { 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") kobaltLog(1, "$zipFilePath looks correct")
} else { } else {