mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 16:07:12 -07:00
Merge branch 'master' of github.com:cbeust/kobalt
This commit is contained in:
commit
49bdec673e
8 changed files with 46 additions and 33 deletions
|
@ -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",
|
||||
|
|
|
@ -1 +1 @@
|
|||
kobalt.version=1.0.60
|
||||
kobalt.version=1.0.62
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
kobalt.version=1.0.60
|
||||
kobalt.version=1.0.62
|
||||
|
|
|
@ -100,15 +100,13 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
|||
val projectName = "p" + Math.abs(Random().nextInt())
|
||||
val version = "1.0"
|
||||
|
||||
fun createFile(root: File, f: String, text: String) : File {
|
||||
val file = File(root, f)
|
||||
file.parentFile.mkdirs()
|
||||
file.writeText(text)
|
||||
return file
|
||||
fun createFile(root: File, f: String, text: String) = File(root, f).apply {
|
||||
parentFile.mkdirs()
|
||||
writeText(text)
|
||||
}
|
||||
|
||||
createFile(root, "kobalt/src/Build.kt",
|
||||
projectInfo.buildFile.text(root.absolutePath, projectName, version))
|
||||
projectInfo.buildFile.text(KFiles.fixSlashes(root.absolutePath), projectName, version))
|
||||
|
||||
projectInfo.files.forEach {
|
||||
createFile(root, it.path, it.content)
|
||||
|
@ -116,18 +114,16 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
|||
return ProjectDescription(root, projectName, version)
|
||||
}
|
||||
|
||||
class LaunchProjectResult(val projectInfo: ProjectInfo, val projectDescription: ProjectDescription,
|
||||
val result: Int)
|
||||
class LaunchProjectResult(val projectDescription: ProjectDescription, val result: Int)
|
||||
|
||||
fun launchProject(projectInfo: ProjectInfo, commandLine: Array<String>) : LaunchProjectResult {
|
||||
val project = createProject(projectInfo)
|
||||
println("Project: $project")
|
||||
val main = Kobalt.INJECTOR.getInstance(Main::class.java)
|
||||
val args = Args()
|
||||
val jc = JCommander(args).apply { parse(*commandLine) }
|
||||
args.buildFile = project.file.absolutePath + "/kobalt/src/Build.kt"
|
||||
args.buildFile = KFiles.fixSlashes(project.file.absolutePath) + "/kobalt/src/Build.kt"
|
||||
val result = Main.launchMain(main, jc, args, arrayOf("assemble"))
|
||||
return LaunchProjectResult(projectInfo, project, result)
|
||||
return LaunchProjectResult(project, result)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,31 +30,35 @@ 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 {
|
||||
// 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
|
||||
|
@ -59,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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue