From 77ca480f5747bb99a1382827517ccf00b9056942 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 19 Feb 2016 05:15:51 +0400 Subject: [PATCH] Fix rootDir problem. --- .../main/kotlin/com/beust/kobalt/FileSpec.kt | 27 +++++++++++-------- .../plugin/packaging/PackagingPlugin.kt | 8 +++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt index 13ed4551..c8f507df 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt @@ -42,19 +42,24 @@ sealed class IFileSpec { val includes = Glob(*spec.toTypedArray()) if (File(filePath).isDirectory) { - val rootDir = if (File(filePath).isAbsolute) Paths.get(filePath) + val rootDir = (if (File(filePath).isAbsolute) Paths.get(filePath) else if (baseDir != null) Paths.get(baseDir, filePath) - else Paths.get(filePath) - Files.walkFileTree(rootDir, object : SimpleFileVisitor() { - override fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult { - val rel = if (baseDir != null && !baseDir.isEmpty()) Paths.get(baseDir).relativize(path) - else path - if (isIncluded(includes, excludes, path)) { - result.add(rel.toFile()) + else Paths.get(filePath)).run { normalize() } + if (rootDir.toFile().exists()) { + Files.walkFileTree(rootDir, object : SimpleFileVisitor() { + override fun visitFile(p: Path, attrs: BasicFileAttributes): FileVisitResult { + val path = p.normalize() + val rel = rootDir.relativize(path) + if (isIncluded(includes, excludes, path)) { + log(2, " including file " + rel.toFile() + " from rootDir $rootDir") + result.add(rel.toFile()) + } + return FileVisitResult.CONTINUE } - return FileVisitResult.CONTINUE - } - }) + }) + } else { + throw AssertionError("$rootDir should exist") + } } else { if (isIncluded(includes, excludes, Paths.get(filePath))) { result.add(File(filePath)) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index e1728a2c..f2a4c2e9 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -50,7 +50,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana val includedSpecs = arrayListOf() includedFile.specs.forEach { spec -> val fromPath = includedFile.from - if (File(fromPath).exists()) { + if (File(directory, fromPath).exists()) { spec.toFiles(directory, fromPath).forEach { file -> val fullFile = File(KFiles.joinDir(directory, fromPath, file.path)) if (! fullFile.exists()) { @@ -247,12 +247,14 @@ class PackageConfig(val project: Project) : AttributeHolder { jar { name = "${project.name}-${project.version}-sources.jar" project.sourceDirectories.forEach { - include(from(project.directory + "/" + it), to(""), glob("**")) + if (File(project.directory, it).exists()) { + include(from(it), to(""), glob("**")) + } } } jar { name = "${project.name}-${project.version}-javadoc.jar" - include(from(project.buildDirectory + "/" + JvmCompilerPlugin.DOCS_DIRECTORY), to(""), glob("**")) + include(from(JvmCompilerPlugin.DOCS_DIRECTORY), to(""), glob("**")) } mainJarAttributes.forEach {