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])
|
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",
|
||||||
|
|
|
@ -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.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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 projectName = "p" + Math.abs(Random().nextInt())
|
||||||
val version = "1.0"
|
val version = "1.0"
|
||||||
|
|
||||||
fun createFile(root: File, f: String, text: String) : File {
|
fun createFile(root: File, f: String, text: String) = File(root, f).apply {
|
||||||
val file = File(root, f)
|
parentFile.mkdirs()
|
||||||
file.parentFile.mkdirs()
|
writeText(text)
|
||||||
file.writeText(text)
|
|
||||||
return file
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createFile(root, "kobalt/src/Build.kt",
|
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 {
|
projectInfo.files.forEach {
|
||||||
createFile(root, it.path, it.content)
|
createFile(root, it.path, it.content)
|
||||||
|
@ -116,18 +114,16 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
||||||
return ProjectDescription(root, projectName, version)
|
return ProjectDescription(root, projectName, version)
|
||||||
}
|
}
|
||||||
|
|
||||||
class LaunchProjectResult(val projectInfo: ProjectInfo, val projectDescription: ProjectDescription,
|
class LaunchProjectResult(val projectDescription: ProjectDescription, val result: Int)
|
||||||
val result: Int)
|
|
||||||
|
|
||||||
fun launchProject(projectInfo: ProjectInfo, commandLine: Array<String>) : LaunchProjectResult {
|
fun launchProject(projectInfo: ProjectInfo, commandLine: Array<String>) : LaunchProjectResult {
|
||||||
val project = createProject(projectInfo)
|
val project = createProject(projectInfo)
|
||||||
println("Project: $project")
|
|
||||||
val main = Kobalt.INJECTOR.getInstance(Main::class.java)
|
val main = Kobalt.INJECTOR.getInstance(Main::class.java)
|
||||||
val args = Args()
|
val args = Args()
|
||||||
val jc = JCommander(args).apply { parse(*commandLine) }
|
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"))
|
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
|
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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue