mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
include() for install{}.
This commit is contained in:
parent
789c969a9b
commit
886b7a4bfa
18 changed files with 214 additions and 191 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
import com.beust.kobalt.*
|
import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.Task
|
import com.beust.kobalt.api.annotation.Task
|
||||||
|
@ -97,6 +98,7 @@ val kobaltPluginApi = project {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile(
|
compile(
|
||||||
|
"org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}",
|
||||||
"com.google.inject:guice:4.0",
|
"com.google.inject:guice:4.0",
|
||||||
"com.google.inject.extensions:guice-assistedinject:4.0",
|
"com.google.inject.extensions:guice-assistedinject:4.0",
|
||||||
"javax.inject:javax.inject:1",
|
"javax.inject:javax.inject:1",
|
||||||
|
@ -114,10 +116,10 @@ val kobaltPluginApi = project {
|
||||||
*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.0",
|
||||||
"org.testng:testng:${Versions.testng}"
|
"org.testng:testng:${Versions.testng}",
|
||||||
|
"commons-io:commons-io:2.5"
|
||||||
)
|
)
|
||||||
exclude(*aether("impl", "spi", "util", "api"))
|
exclude(*aether("impl", "spi", "util", "api"))
|
||||||
compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.1")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,7 +156,9 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
compile("org.jetbrains.kotlin:kotlin-compiler-embeddable:${Versions.kotlin}")
|
compile("org.jetbrains.kotlin:kotlin-compiler-embeddable:${Versions.kotlin}")
|
||||||
|
|
||||||
// Used by the main app
|
// Used by the main app
|
||||||
compile("com.github.spullara.mustache.java:compiler:0.9.1",
|
compile(
|
||||||
|
"org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}",
|
||||||
|
"com.github.spullara.mustache.java:compiler:0.9.1",
|
||||||
"javax.inject:javax.inject:1",
|
"javax.inject:javax.inject:1",
|
||||||
"com.google.inject:guice:4.0",
|
"com.google.inject:guice:4.0",
|
||||||
"com.google.inject.extensions:guice-assistedinject:4.0",
|
"com.google.inject.extensions:guice-assistedinject:4.0",
|
||||||
|
@ -181,16 +185,15 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
// "org.glassfish.jersey.media:jersey-media-moxy:${Versions.jersey}",
|
// "org.glassfish.jersey.media:jersey-media-moxy:${Versions.jersey}",
|
||||||
// "org.wasabi:wasabi:0.1.182"
|
// "org.wasabi:wasabi:0.1.182"
|
||||||
)
|
)
|
||||||
compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.1")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependenciesTest {
|
dependenciesTest {
|
||||||
compile("org.testng:testng:${Versions.testng}",
|
compile("org.jetbrains.kotlin:kotlin-test:${Versions.kotlin}",
|
||||||
|
"org.testng:testng:${Versions.testng}",
|
||||||
"org.assertj:assertj-core:3.4.1",
|
"org.assertj:assertj-core:3.4.1",
|
||||||
*mavenResolver("util")
|
*mavenResolver("util")
|
||||||
)
|
)
|
||||||
compile("org.jetbrains.kotlin:kotlin-test:1.1.1")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assemble {
|
assemble {
|
||||||
|
@ -202,12 +205,15 @@ val kobaltApp = project(kobaltPluginApi, wrapper) {
|
||||||
}
|
}
|
||||||
zip {
|
zip {
|
||||||
val dir = "kobalt-$version"
|
val dir = "kobalt-$version"
|
||||||
include(from("dist"), to("$dir/bin"), "kobaltw")
|
val files = listOf(
|
||||||
include(from("dist"), to("$dir/bin"), "kobaltw.bat")
|
"dist", "$dir/bin", "kobaltw",
|
||||||
include(from("$buildDirectory/libs"), to("$dir/kobalt/wrapper"),
|
"dist", "$dir/bin", "kobaltw.bat",
|
||||||
"$projectName-$version.jar")
|
"$buildDirectory/libs", "$dir/kobalt/wrapper", "$projectName-$version.jar",
|
||||||
include(from("modules/wrapper/$buildDirectory/libs"), to("$dir/kobalt/wrapper"),
|
"modules/wrapper/$buildDirectory/libs", "$dir/kobalt/wrapper", "$projectName-wrapper.jar")
|
||||||
"$projectName-wrapper.jar")
|
|
||||||
|
(0 .. files.size - 1 step 3).forEach { i ->
|
||||||
|
include(from(files[i]), To(files[i + 1]), files[i + 2])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.beust.kobalt
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.archive.Zip
|
import com.beust.kobalt.archive.Zip
|
||||||
import com.beust.kobalt.misc.IncludedFile
|
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.beust.kobalt
|
||||||
|
|
||||||
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base classes for directives that support install(from,to) (e.g. install{} or jar{}).
|
||||||
|
*/
|
||||||
|
open class IncludeFromTo {
|
||||||
|
/**
|
||||||
|
* Prefix path to be removed from the zip file. For example, if you add "build/lib/a.jar" to the zip
|
||||||
|
* file and the excludePrefix is "build/lib", then "a.jar" will be added at the root of the zip file.
|
||||||
|
*/
|
||||||
|
val includedFiles = arrayListOf<IncludedFile>()
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun from(s: String) = From(s)
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun to(s: String) = To(s)
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun include(vararg files: String) {
|
||||||
|
includedFiles.add(IncludedFile(files.map { IFileSpec.FileSpec(it) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun include(from: From, to: To, vararg specs: String) {
|
||||||
|
includedFiles.add(IncludedFile(from, to, specs.map { IFileSpec.FileSpec(it) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun include(from: From, to: To, vararg specs: IFileSpec.GlobSpec) {
|
||||||
|
includedFiles.add(IncludedFile(from, to, listOf(*specs)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.beust.kobalt
|
||||||
|
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import com.beust.kobalt.misc.toString
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List<IFileSpec>,
|
||||||
|
val expandJarFiles: Boolean = false) {
|
||||||
|
constructor(specs: List<IFileSpec>, expandJarFiles: Boolean = false) : this(From(""), To(""), specs, expandJarFiles)
|
||||||
|
fun from(s: String) = File(if (fromOriginal.isCurrentDir()) s else KFiles.joinDir(from, s))
|
||||||
|
val from: String get() = fromOriginal.path.replace("\\", "/")
|
||||||
|
fun to(s: String) = File(if (toOriginal.isCurrentDir()) s else KFiles.joinDir(to, s))
|
||||||
|
val to: String get() = toOriginal.path.replace("\\", "/")
|
||||||
|
override fun toString() = toString("IncludedFile",
|
||||||
|
"files - ", specs.map { it.toString() },
|
||||||
|
"from", from,
|
||||||
|
"to", to)
|
||||||
|
|
||||||
|
fun allFromFiles(directory: String? = null): List<File> {
|
||||||
|
val result = arrayListOf<File>()
|
||||||
|
specs.forEach { spec ->
|
||||||
|
// val fullDir = if (directory == null) from else KFiles.joinDir(directory, from)
|
||||||
|
spec.toFiles(directory, from).forEach { source ->
|
||||||
|
result.add(if (source.isAbsolute) source else File(source.path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.map { Paths.get(it.path).normalize().toFile()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class Direction(open val p: String) {
|
||||||
|
override fun toString() = path
|
||||||
|
fun isCurrentDir() = path == "./"
|
||||||
|
|
||||||
|
val path: String get() =
|
||||||
|
if (p.isEmpty()) "./"
|
||||||
|
else if (p.startsWith("/") || p.endsWith("/")) p
|
||||||
|
else p + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
class From(override val p: String) : Direction(p)
|
||||||
|
|
||||||
|
class To(override val p: String) : Direction(p)
|
|
@ -1,11 +1,12 @@
|
||||||
package com.beust.kobalt.archive
|
package com.beust.kobalt.archive
|
||||||
|
|
||||||
import com.beust.kobalt.Features
|
import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.IFileSpec
|
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.ExportedProjectProperty
|
import com.beust.kobalt.api.annotation.ExportedProjectProperty
|
||||||
import com.beust.kobalt.misc.*
|
import com.beust.kobalt.misc.JarUtils
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import com.beust.kobalt.misc.kobaltLog
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
|
@ -1,23 +1,13 @@
|
||||||
package com.beust.kobalt.archive
|
package com.beust.kobalt.archive
|
||||||
|
|
||||||
import com.beust.kobalt.Glob
|
import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.IFileSpec
|
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
import com.beust.kobalt.misc.From
|
|
||||||
import com.beust.kobalt.misc.IncludedFile
|
|
||||||
import com.beust.kobalt.misc.To
|
|
||||||
|
|
||||||
open class Zip(open val project: Project, open var name: String = Archives.defaultArchiveName(project) + ".zip",
|
open class Zip(open val project: Project, open var name: String = Archives.defaultArchiveName(project) + ".zip",
|
||||||
open var fatJar: Boolean = false): AttributeHolder {
|
open var fatJar: Boolean = false): AttributeHolder, IncludeFromTo() {
|
||||||
val excludes = arrayListOf<Glob>()
|
val excludes = arrayListOf<Glob>()
|
||||||
|
|
||||||
@Directive
|
|
||||||
fun from(s: String) = From(s)
|
|
||||||
|
|
||||||
@Directive
|
|
||||||
fun to(s: String) = To(s)
|
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
fun exclude(vararg files: String) {
|
fun exclude(vararg files: String) {
|
||||||
files.forEach { excludes.add(Glob(it)) }
|
files.forEach { excludes.add(Glob(it)) }
|
||||||
|
@ -28,34 +18,10 @@ open class Zip(open val project: Project, open var name: String = Archives.defau
|
||||||
specs.forEach { excludes.add(it) }
|
specs.forEach { excludes.add(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive
|
|
||||||
fun include(vararg files: String) {
|
|
||||||
includedFiles.add(IncludedFile(files.map { IFileSpec.FileSpec(it) }))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Directive
|
|
||||||
fun include(from: From, to: To, vararg specs: String) {
|
|
||||||
includedFiles.add(IncludedFile(from, to, specs.map { IFileSpec.FileSpec(it) }))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Directive
|
|
||||||
fun include(from: From, to: To, vararg specs: IFileSpec.GlobSpec) {
|
|
||||||
includedFiles.add(IncludedFile(from, to, listOf(*specs)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prefix path to be removed from the zip file. For example, if you add "build/lib/a.jar" to the zip
|
|
||||||
* file and the excludePrefix is "build/lib", then "a.jar" will be added at the root of the zip file.
|
|
||||||
*/
|
|
||||||
val includedFiles = arrayListOf<IncludedFile>()
|
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
open val attributes = arrayListOf(Pair("Manifest-Version", "1.0"))
|
open val attributes = arrayListOf(Pair("Manifest-Version", "1.0"))
|
||||||
|
|
||||||
override fun addAttribute(k: String, v: String) {
|
override fun addAttribute(k: String, v: String) {
|
||||||
attributes.add(Pair(k, v))
|
attributes.add(Pair(k, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager
|
||||||
.filter(File::exists)
|
.filter(File::exists)
|
||||||
.forEach {
|
.forEach {
|
||||||
context.logger.log(project.name, 2, "Copying from $it to $absOutputDir")
|
context.logger.log(project.name, 2, "Copying from $it to $absOutputDir")
|
||||||
KFiles.copyRecursively(it, absOutputDir, deleteFirst = false)
|
KFiles.copyRecursively(it, absOutputDir, replaceExisting = true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context.logger.log(project.name, 2, "No resources to copy for $sourceSet")
|
context.logger.log(project.name, 2, "No resources to copy for $sourceSet")
|
||||||
|
|
|
@ -175,13 +175,13 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors,
|
||||||
* TODO: This should be private, everyone should be calling calculateDependencies().
|
* TODO: This should be private, everyone should be calling calculateDependencies().
|
||||||
*/
|
*/
|
||||||
fun transitiveClosure(dependencies : List<IClasspathDependency>,
|
fun transitiveClosure(dependencies : List<IClasspathDependency>,
|
||||||
dependencyFilter: DependencyFilter? = null,
|
filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER,
|
||||||
requiredBy: String? = null): List<IClasspathDependency> {
|
requiredBy: String? = null): List<IClasspathDependency> {
|
||||||
val result = arrayListOf<IClasspathDependency>()
|
val result = arrayListOf<IClasspathDependency>()
|
||||||
dependencies.forEach { dependency ->
|
dependencies.forEach { dependency ->
|
||||||
result.add(dependency)
|
result.add(dependency)
|
||||||
if (dependency.isMaven) {
|
if (dependency.isMaven) {
|
||||||
val resolved = resolver.resolveToIds(dependency.id, null, dependencyFilter).map { create(it) }
|
val resolved = resolver.resolveToIds(dependency.id, null, filter).map { create(it) }
|
||||||
result.addAll(resolved)
|
result.addAll(resolved)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,12 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
fun isRangeVersion(id: String) = id.contains(",")
|
fun isRangeVersion(id: String) = id.contains(",")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolveToArtifact(id: String, scope: Scope? = null, filter: DependencyFilter? = null) : Artifact
|
fun resolveToArtifact(id: String, scope: Scope? = null,
|
||||||
|
filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER) : Artifact
|
||||||
= resolve(id, scope, filter).root.artifact
|
= resolve(id, scope, filter).root.artifact
|
||||||
|
|
||||||
fun resolve(id: String, scope: Scope? = null, filter: DependencyFilter? = null,
|
fun resolve(id: String, scope: Scope? = null,
|
||||||
|
filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER,
|
||||||
repos: List<String> = emptyList()): DependencyResult {
|
repos: List<String> = emptyList()): DependencyResult {
|
||||||
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter)
|
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter)
|
||||||
val result = system.resolveDependencies(session, dependencyRequest)
|
val result = system.resolveDependencies(session, dependencyRequest)
|
||||||
|
@ -46,10 +48,12 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolve(artifact: Artifact, scope: Scope? = null, filter: DependencyFilter? = null)
|
fun resolve(artifact: Artifact, scope: Scope? = null,
|
||||||
|
filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER)
|
||||||
= resolve(artifactToId(artifact), scope, filter)
|
= resolve(artifactToId(artifact), scope, filter)
|
||||||
|
|
||||||
fun resolveToIds(id: String, scope: Scope? = null, filter: DependencyFilter? = null,
|
fun resolveToIds(id: String, scope: Scope? = null,
|
||||||
|
filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER,
|
||||||
seen: HashSet<String> = hashSetOf<String>()) : List<String> {
|
seen: HashSet<String> = hashSetOf<String>()) : List<String> {
|
||||||
val rr = resolve(id, scope, filter)
|
val rr = resolve(id, scope, filter)
|
||||||
val children =
|
val children =
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
import com.beust.kobalt.Glob
|
import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.IFileSpec
|
|
||||||
import com.google.common.io.CharStreams
|
import com.google.common.io.CharStreams
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.nio.file.Paths
|
|
||||||
import java.util.jar.JarEntry
|
import java.util.jar.JarEntry
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
import java.util.jar.JarInputStream
|
import java.util.jar.JarInputStream
|
||||||
|
@ -134,39 +132,3 @@ class JarUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class Direction(open val p: String) {
|
|
||||||
override fun toString() = path
|
|
||||||
fun isCurrentDir() = path == "./"
|
|
||||||
val path: String get() =
|
|
||||||
if (p.isEmpty()) "./"
|
|
||||||
else if (p.startsWith("/") || p.endsWith("/")) p
|
|
||||||
else p + "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List<IFileSpec>,
|
|
||||||
val expandJarFiles: Boolean = false) {
|
|
||||||
constructor(specs: List<IFileSpec>, expandJarFiles: Boolean = false) : this(From(""), To(""), specs, expandJarFiles)
|
|
||||||
fun from(s: String) = File(if (fromOriginal.isCurrentDir()) s else KFiles.joinDir(from, s))
|
|
||||||
val from: String get() = fromOriginal.path.replace("\\", "/")
|
|
||||||
fun to(s: String) = File(if (toOriginal.isCurrentDir()) s else KFiles.joinDir(to, s))
|
|
||||||
val to: String get() = toOriginal.path.replace("\\", "/")
|
|
||||||
override fun toString() = toString("IncludedFile",
|
|
||||||
"files - ", specs.map { it.toString() },
|
|
||||||
"from", from,
|
|
||||||
"to", to)
|
|
||||||
|
|
||||||
fun allFromFiles(directory: String? = null): List<File> {
|
|
||||||
val result = arrayListOf<File>()
|
|
||||||
specs.forEach { spec ->
|
|
||||||
// val fullDir = if (directory == null) from else KFiles.joinDir(directory, from)
|
|
||||||
spec.toFiles(directory, from).forEach { source ->
|
|
||||||
result.add(if (source.isAbsolute) source else File(source.path))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result.map { Paths.get(it.path).normalize().toFile()}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class From(override val p: String) : Direction(p)
|
|
||||||
|
|
||||||
class To(override val p: String) : Direction(p)
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.maven.Md5
|
import com.beust.kobalt.maven.Md5
|
||||||
|
import org.apache.commons.io.FileUtils
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
@ -11,6 +12,7 @@ import java.nio.file.Paths
|
||||||
import java.nio.file.StandardCopyOption
|
import java.nio.file.StandardCopyOption
|
||||||
import java.util.jar.JarInputStream
|
import java.util.jar.JarInputStream
|
||||||
|
|
||||||
|
|
||||||
class KFiles {
|
class KFiles {
|
||||||
/**
|
/**
|
||||||
* This actually returns a list of strings because in development mode, we are not pointing to a single
|
* This actually returns a list of strings because in development mode, we are not pointing to a single
|
||||||
|
@ -194,69 +196,6 @@ class KFiles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun copyRecursively(from: File, to: File, replaceExisting: Boolean = true, deleteFirst: Boolean = false,
|
|
||||||
onError: (File, IOException) -> OnErrorAction = { _, 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 = replaceExisting, onError = 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 =
|
|
||||||
{ _, 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().onFail { 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(KFiles.joinDir(dst.path, relPath.path))
|
|
||||||
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 (Features.USE_TIMESTAMPS && dstFile.exists() && Md5.toMd5(src) == Md5.toMd5(dstFile)) {
|
|
||||||
kobaltLog(3, " Identical files, not copying $src to $dstFile")
|
|
||||||
} else {
|
|
||||||
val target = src.copyTo(dstFile, true)
|
|
||||||
if (target.length() != src.length()) {
|
|
||||||
if (onError(src,
|
|
||||||
IOException("src.length() != dst.length()")) == OnErrorAction.TERMINATE)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
} catch (e: TerminateException) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The build location for build scripts is .kobalt/build
|
* The build location for build scripts is .kobalt/build
|
||||||
*/
|
*/
|
||||||
|
@ -386,6 +325,29 @@ class KFiles {
|
||||||
}
|
}
|
||||||
|
|
||||||
val dotKobaltDir = File(KFiles.joinAndMakeDir(KFiles.KOBALT_DOT_DIR))
|
val dotKobaltDir = File(KFiles.joinAndMakeDir(KFiles.KOBALT_DOT_DIR))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn the IncludedFiles into actual Files
|
||||||
|
*/
|
||||||
|
fun materializeIncludedFiles(project: Project, includedFiles: List<IncludedFile>) : List<File> {
|
||||||
|
val result = includedFiles.fold(arrayListOf<File>()) { files, includedFile: IncludedFile ->
|
||||||
|
val foundFiles = includedFile.allFromFiles(project.directory)
|
||||||
|
val absFiles = foundFiles.map {
|
||||||
|
File(KFiles.joinDir(project.directory, includedFile.from, it.path))
|
||||||
|
}
|
||||||
|
files.addAll(absFiles)
|
||||||
|
files
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
fun copyRecursively(from: File, to: File, replaceExisting: Boolean = true, deleteFirst: Boolean = false) {
|
||||||
|
// fun copy(relativePath: String, sourceDir: File, targetDir: File) =
|
||||||
|
// sourceDir.resolve(relativePath).copyRecursively(targetDir.resolve(relativePath), overwrite = true)
|
||||||
|
if (from.isFile) FileUtils.copyFileToDirectory(from, to)
|
||||||
|
else FileUtils.copyDirectory(from, to)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findRecursively(directory: File, function: Function1<String, Boolean>): List<String> {
|
fun findRecursively(directory: File, function: Function1<String, Boolean>): List<String> {
|
||||||
|
|
|
@ -12,11 +12,11 @@ import com.beust.kobalt.internal.ParallelLogger
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.maven.Md5
|
import com.beust.kobalt.maven.Md5
|
||||||
import com.beust.kobalt.maven.PomGenerator
|
import com.beust.kobalt.maven.PomGenerator
|
||||||
import com.beust.kobalt.misc.IncludedFile
|
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.benchmarkMillis
|
import com.beust.kobalt.misc.benchmarkMillis
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.file.Paths
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@ -107,14 +107,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
context.variant.archiveName(project, null, ".jar"))
|
context.variant.archiveName(project, null, ".jar"))
|
||||||
|
|
||||||
// Turn the IncludedFiles into actual Files
|
// Turn the IncludedFiles into actual Files
|
||||||
val inputFiles = allIncludedFiles.fold(arrayListOf<File>()) { files, includedFile: IncludedFile ->
|
val inputFiles = KFiles.materializeIncludedFiles(project, allIncludedFiles)
|
||||||
val foundFiles = includedFile.allFromFiles(project.directory)
|
|
||||||
val absFiles = foundFiles.map {
|
|
||||||
File(KFiles.joinDir(project.directory, includedFile.from, it.path))
|
|
||||||
}
|
|
||||||
files.addAll(absFiles)
|
|
||||||
files
|
|
||||||
}
|
|
||||||
|
|
||||||
val inMd5 = Md5.toMd5Directories(inputFiles)
|
val inMd5 = Md5.toMd5Directories(inputFiles)
|
||||||
val outMd5 = Md5.toMd5Directories(outputFiles)
|
val outMd5 = Md5.toMd5Directories(outputFiles)
|
||||||
|
@ -221,10 +214,24 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
val buildDir = project.projectProperties.getString(LIBS_DIR)
|
val buildDir = project.projectProperties.getString(LIBS_DIR)
|
||||||
val buildDirFile = File(buildDir)
|
val buildDirFile = File(buildDir)
|
||||||
if (buildDirFile.exists()) {
|
if (buildDirFile.exists()) {
|
||||||
context.logger.log(project.name, 1, "Installing from $buildDir to ${config.libDir}")
|
|
||||||
|
|
||||||
val toDir = KFiles.makeDir(config.libDir)
|
if (config.includedFiles.isEmpty()) {
|
||||||
KFiles.copyRecursively(buildDirFile, toDir, deleteFirst = true)
|
context.logger.log(project.name, 1, " Installing from $buildDir to ${config.libDir}")
|
||||||
|
val toDir = KFiles.makeDir(config.libDir)
|
||||||
|
File(buildDir).copyRecursively(toDir, overwrite = true)
|
||||||
|
} else {
|
||||||
|
config.includedFiles.forEach { inf ->
|
||||||
|
val target = inf.to
|
||||||
|
val targetFile = File(target)
|
||||||
|
targetFile.deleteRecursively()
|
||||||
|
targetFile.mkdirs()
|
||||||
|
val files = KFiles.materializeIncludedFiles(project, listOf(inf))
|
||||||
|
files.forEach {
|
||||||
|
context.logger.log(project.name, 1, " Installing $it to $targetFile")
|
||||||
|
KFiles.copyRecursively(it, targetFile, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TaskResult()
|
return TaskResult()
|
||||||
|
@ -242,7 +249,7 @@ fun Project.install(init: InstallConfig.() -> Unit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InstallConfig(var libDir : String = "libs")
|
class InstallConfig(var libDir : String = "libs") : IncludeFromTo()
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
fun Project.assemble(init: PackageConfig.(p: Project) -> Unit): PackageConfig = let {
|
fun Project.assemble(init: PackageConfig.(p: Project) -> Unit): PackageConfig = let {
|
||||||
|
@ -292,14 +299,14 @@ class PackageConfig(val project: Project) : AttributeHolder {
|
||||||
name = "${project.name}-${project.version}-sources.jar"
|
name = "${project.name}-${project.version}-sources.jar"
|
||||||
project.sourceDirectories.forEach {
|
project.sourceDirectories.forEach {
|
||||||
if (File(project.directory, it).exists()) {
|
if (File(project.directory, it).exists()) {
|
||||||
include(from(it), to(""), glob("**"))
|
include(From(it), To(""), glob("**"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jar {
|
jar {
|
||||||
name = "${project.name}-${project.version}-javadoc.jar"
|
name = "${project.name}-${project.version}-javadoc.jar"
|
||||||
val fromDir = KFiles.joinDir(project.buildDirectory, JvmCompilerPlugin.DOCS_DIRECTORY)
|
val fromDir = KFiles.joinDir(project.buildDirectory, JvmCompilerPlugin.DOCS_DIRECTORY)
|
||||||
include(from(fromDir), to(""), glob("**"))
|
include(From(fromDir), To(""), glob("**"))
|
||||||
}
|
}
|
||||||
|
|
||||||
mainJarAttributes.forEach {
|
mainJarAttributes.forEach {
|
||||||
|
@ -331,3 +338,19 @@ class Pom {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val realSource = File("/tmp/a")
|
||||||
|
val sourceDir = File(realSource, "b").apply { mkdirs() }
|
||||||
|
val from = File(sourceDir, "foo").apply { writeText("I'm a file") }
|
||||||
|
val to = File("/tmp/to").apply {
|
||||||
|
deleteRecursively()
|
||||||
|
mkdirs()
|
||||||
|
}
|
||||||
|
val sourcePath = Paths.get(realSource.toURI())
|
||||||
|
val targetPath = Paths.get(to.toURI())
|
||||||
|
// Files.walkFileTree(sourcePath, KFiles.Companion.CopyFileVisitor(targetPath))
|
||||||
|
|
||||||
|
if (! to.isDirectory) {
|
||||||
|
throw AssertionError("Should be a directory")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package com.beust.kobalt.plugin.packaging
|
package com.beust.kobalt.plugin.packaging
|
||||||
|
|
||||||
import com.beust.kobalt.ArchiveGenerator
|
import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.IFileSpec
|
|
||||||
import com.beust.kobalt.JarGenerator
|
|
||||||
import com.beust.kobalt.api.IClasspathDependency
|
import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
@ -10,10 +8,7 @@ import com.beust.kobalt.archive.Archives
|
||||||
import com.beust.kobalt.archive.Zip
|
import com.beust.kobalt.archive.Zip
|
||||||
import com.beust.kobalt.internal.ParallelLogger
|
import com.beust.kobalt.internal.ParallelLogger
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.misc.From
|
|
||||||
import com.beust.kobalt.misc.IncludedFile
|
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.To
|
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.beust.kobalt.plugin.packaging
|
package com.beust.kobalt.plugin.packaging
|
||||||
|
|
||||||
import com.beust.kobalt.ArchiveGenerator
|
import com.beust.kobalt.ArchiveGenerator
|
||||||
|
import com.beust.kobalt.IncludedFile
|
||||||
import com.beust.kobalt.JarGenerator
|
import com.beust.kobalt.JarGenerator
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
@ -8,7 +9,6 @@ import com.beust.kobalt.archive.Archives
|
||||||
import com.beust.kobalt.archive.Zip
|
import com.beust.kobalt.archive.Zip
|
||||||
import com.beust.kobalt.internal.ParallelLogger
|
import com.beust.kobalt.internal.ParallelLogger
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.misc.IncludedFile
|
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
|
||||||
class ZipGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger)
|
class ZipGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger)
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package com.beust.kobalt
|
package com.beust.kobalt
|
||||||
|
|
||||||
import com.beust.kobalt.misc.From
|
|
||||||
import com.beust.kobalt.misc.IncludedFile
|
|
||||||
import com.beust.kobalt.misc.To
|
|
||||||
import org.testng.Assert
|
import org.testng.Assert
|
||||||
import org.testng.annotations.BeforeClass
|
import org.testng.annotations.BeforeClass
|
||||||
import org.testng.annotations.DataProvider
|
import org.testng.annotations.DataProvider
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
package com.beust.kobalt.maven
|
package com.beust.kobalt.maven
|
||||||
|
|
||||||
import com.beust.kobalt.IFileSpec
|
import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.homeDir
|
|
||||||
import com.beust.kobalt.misc.From
|
|
||||||
import com.beust.kobalt.misc.IncludedFile
|
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.To
|
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
@Test(enabled = false)
|
@Test(enabled = false)
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
|
import com.beust.kobalt.From
|
||||||
import com.beust.kobalt.IFileSpec
|
import com.beust.kobalt.IFileSpec
|
||||||
|
import com.beust.kobalt.IncludedFile
|
||||||
|
import com.beust.kobalt.To
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.testng.Assert
|
import org.testng.Assert
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
class IncludedFileTest {
|
class IncludedFileTest {
|
||||||
|
@ -14,4 +19,28 @@ class IncludedFileTest {
|
||||||
Assert.assertTrue(it.exists(), "Should exist: $it")
|
Assert.assertTrue(it.exists(), "Should exist: $it")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun shouldRecursivelyCopy() {
|
||||||
|
val TEXT = "I'm a file"
|
||||||
|
val ROOT = Files.createTempDirectory("kobalt-test").toFile()
|
||||||
|
val from = File(ROOT, "from")
|
||||||
|
File(from, "a/b").apply { mkdirs() }
|
||||||
|
val file = File("/a/b/foo")
|
||||||
|
File(from, file.path).apply { writeText(TEXT) }
|
||||||
|
val to = File(ROOT, "to").apply {
|
||||||
|
deleteRecursively()
|
||||||
|
mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
val targetFile = File(to, file.path)
|
||||||
|
assertThat(targetFile).doesNotExist()
|
||||||
|
|
||||||
|
KFiles.copyRecursively(from, to)
|
||||||
|
|
||||||
|
assertThat(to).isDirectory()
|
||||||
|
with(targetFile) {
|
||||||
|
assertThat(this).exists()
|
||||||
|
assertThat(this.readText()).isEqualTo(TEXT)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
|
import com.beust.kobalt.From
|
||||||
import com.beust.kobalt.IFileSpec
|
import com.beust.kobalt.IFileSpec
|
||||||
|
import com.beust.kobalt.IncludedFile
|
||||||
|
import com.beust.kobalt.To
|
||||||
import org.testng.Assert
|
import org.testng.Assert
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue