mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
include() for install{}.
This commit is contained in:
parent
789c969a9b
commit
886b7a4bfa
18 changed files with 214 additions and 191 deletions
|
@ -12,11 +12,11 @@ import com.beust.kobalt.internal.ParallelLogger
|
|||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.Md5
|
||||
import com.beust.kobalt.maven.PomGenerator
|
||||
import com.beust.kobalt.misc.IncludedFile
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.benchmarkMillis
|
||||
import java.io.File
|
||||
import java.nio.file.Paths
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -107,14 +107,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
context.variant.archiveName(project, null, ".jar"))
|
||||
|
||||
// Turn the IncludedFiles into actual Files
|
||||
val inputFiles = allIncludedFiles.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
|
||||
}
|
||||
val inputFiles = KFiles.materializeIncludedFiles(project, allIncludedFiles)
|
||||
|
||||
val inMd5 = Md5.toMd5Directories(inputFiles)
|
||||
val outMd5 = Md5.toMd5Directories(outputFiles)
|
||||
|
@ -221,10 +214,24 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
val buildDir = project.projectProperties.getString(LIBS_DIR)
|
||||
val buildDirFile = File(buildDir)
|
||||
if (buildDirFile.exists()) {
|
||||
context.logger.log(project.name, 1, "Installing from $buildDir to ${config.libDir}")
|
||||
|
||||
val toDir = KFiles.makeDir(config.libDir)
|
||||
KFiles.copyRecursively(buildDirFile, toDir, deleteFirst = true)
|
||||
if (config.includedFiles.isEmpty()) {
|
||||
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()
|
||||
|
@ -242,7 +249,7 @@ fun Project.install(init: InstallConfig.() -> Unit) {
|
|||
}
|
||||
}
|
||||
|
||||
class InstallConfig(var libDir : String = "libs")
|
||||
class InstallConfig(var libDir : String = "libs") : IncludeFromTo()
|
||||
|
||||
@Directive
|
||||
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"
|
||||
project.sourceDirectories.forEach {
|
||||
if (File(project.directory, it).exists()) {
|
||||
include(from(it), to(""), glob("**"))
|
||||
include(From(it), To(""), glob("**"))
|
||||
}
|
||||
}
|
||||
}
|
||||
jar {
|
||||
name = "${project.name}-${project.version}-javadoc.jar"
|
||||
val fromDir = KFiles.joinDir(project.buildDirectory, JvmCompilerPlugin.DOCS_DIRECTORY)
|
||||
include(from(fromDir), to(""), glob("**"))
|
||||
include(From(fromDir), To(""), glob("**"))
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
import com.beust.kobalt.ArchiveGenerator
|
||||
import com.beust.kobalt.IFileSpec
|
||||
import com.beust.kobalt.JarGenerator
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
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.internal.ParallelLogger
|
||||
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.To
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
import java.io.OutputStream
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.beust.kobalt.plugin.packaging
|
||||
|
||||
import com.beust.kobalt.ArchiveGenerator
|
||||
import com.beust.kobalt.IncludedFile
|
||||
import com.beust.kobalt.JarGenerator
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
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.internal.ParallelLogger
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.misc.IncludedFile
|
||||
import com.google.inject.Inject
|
||||
|
||||
class ZipGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger)
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
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.annotations.BeforeClass
|
||||
import org.testng.annotations.DataProvider
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.IFileSpec
|
||||
import com.beust.kobalt.homeDir
|
||||
import com.beust.kobalt.misc.From
|
||||
import com.beust.kobalt.misc.IncludedFile
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.To
|
||||
import org.testng.annotations.Test
|
||||
|
||||
@Test(enabled = false)
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import com.beust.kobalt.From
|
||||
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.annotations.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
@Test
|
||||
class IncludedFileTest {
|
||||
|
@ -14,4 +19,28 @@ class IncludedFileTest {
|
|||
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
|
||||
|
||||
import com.beust.kobalt.From
|
||||
import com.beust.kobalt.IFileSpec
|
||||
import com.beust.kobalt.IncludedFile
|
||||
import com.beust.kobalt.To
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
import javax.inject.Inject
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue