From 732f17b7b723e55a3cd457315b91eb4583dc3452 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 30 Nov 2015 22:44:24 -0800 Subject: [PATCH 1/5] Warnings. --- src/main/kotlin/com/beust/kobalt/Main.kt | 4 ++-- .../kotlin/com/beust/kobalt/maven/DependencyManager.kt | 8 +------- src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt | 2 +- src/main/kotlin/com/beust/kobalt/misc/Benchmarks.kt | 2 +- src/main/kotlin/com/beust/kobalt/misc/LocalProperties.kt | 2 +- .../com/beust/kobalt/plugin/android/AndroidFiles.kt | 7 +++---- .../com/beust/kobalt/plugin/android/AndroidPlugin.kt | 6 ++---- src/main/kotlin/com/beust/kobalt/plugin/android/Merger.kt | 2 +- .../beust/kobalt/plugin/application/ApplicationPlugin.kt | 2 ++ .../com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt | 2 +- .../com/beust/kobalt/plugin/packaging/PackagingPlugin.kt | 4 ++-- .../com/beust/kobalt/plugin/publish/PublishPlugin.kt | 3 ++- 12 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index 65ca6490..c8e974b3 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -93,7 +93,7 @@ private class Main @Inject constructor( var result = 0 val latestVersionFuture = github.latestKobaltVersion - val seconds = benchmark("build", { + val seconds = benchmark { try { result = runWithArgs(jc, args, argv) } catch(ex: KobaltException) { @@ -102,7 +102,7 @@ private class Main @Inject constructor( } finally { executors.shutdown() } - }) + } log(1, if (result != 0) "BUILD FAILED: $result" else "BUILD SUCCESSFUL ($seconds seconds)") diff --git a/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index f71359d6..00b60956 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -4,7 +4,6 @@ import com.beust.kobalt.api.* import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors -import com.beust.kobalt.misc.warn import com.google.common.collect.ArrayListMultimap import java.util.* import javax.inject.Inject @@ -98,12 +97,7 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor it.project.name == project?.name }.forEach { pd -> pd.dependsOn.forEach { p -> - val classesDir = p.classesDir(context) - if (classesDir != null) { - result.add(FileDependency(KFiles.joinDir(p.directory, classesDir))) - } else { - warn("Couldn't find any classes dir for project depended on ${p.name}") - } + result.add(FileDependency(KFiles.joinDir(p.directory, p.classesDir(context)))) val otherDependencies = calculateDependencies(p, context, projectDescriptions, p.compileDependencies) result.addAll(otherDependencies) diff --git a/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt b/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt index c038d71a..d4853dd3 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt @@ -52,7 +52,7 @@ public class PomGenerator @Inject constructor(@Assisted val project: Project) { val s = StringWriter() MavenXpp3Writer().write(s, m) - val buildDir = KFiles.makeDir(project.directory, project.buildDirectory!!) + val buildDir = KFiles.makeDir(project.directory, project.buildDirectory) val outputDir = KFiles.makeDir(buildDir.path, "libs") val mavenId = MavenId.create(project.group!!, project.artifactId!!, project.packaging, project.version!!) val pomFile = SimpleDep(mavenId).toPomFileName() diff --git a/src/main/kotlin/com/beust/kobalt/misc/Benchmarks.kt b/src/main/kotlin/com/beust/kobalt/misc/Benchmarks.kt index 41661136..70378e2f 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/Benchmarks.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/Benchmarks.kt @@ -1,6 +1,6 @@ package com.beust.kobalt.misc -public fun benchmark(message: String, run: () -> Unit) : Long { +public fun benchmark(run: () -> Unit) : Long { val start = System.currentTimeMillis() run() return (System.currentTimeMillis() - start) / 1000 diff --git a/src/main/kotlin/com/beust/kobalt/misc/LocalProperties.kt b/src/main/kotlin/com/beust/kobalt/misc/LocalProperties.kt index 371d106d..182fe42a 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/LocalProperties.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/LocalProperties.kt @@ -29,7 +29,7 @@ class LocalProperties { fun get(name: String, docUrl: String? = null) : String { this.docUrl = docUrl - val result = localProperties[name] + val result = localProperties.getProperty(name) ?: throw KobaltException("Couldn't find $name in local.properties", docUrl = docUrl) return result as String } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidFiles.kt b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidFiles.kt index 5ba54f7f..6b31f01a 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidFiles.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidFiles.kt @@ -1,7 +1,6 @@ package com.beust.kobalt.plugin.android import com.beust.kobalt.Variant -import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project import com.beust.kobalt.misc.KFiles @@ -12,7 +11,7 @@ class AndroidFiles { fun intermediates(project: Project) = KFiles.joinDir(project.directory, project.buildDirectory, "intermediates") - fun manifest(project: Project, context: KobaltContext) : String { + fun manifest(project: Project) : String { return KFiles.joinDir(project.directory, "src/main", "AndroidManifest.xml") } @@ -21,10 +20,10 @@ class AndroidFiles { return KFiles.joinDir(dir, "AndroidManifest.xml") } - fun mergedResourcesNoVariant(project: Project, variant: Variant) = + fun mergedResourcesNoVariant(project: Project) = KFiles.joinAndMakeDir(AndroidFiles.intermediates(project), "res", "merged") fun mergedResources(project: Project, variant: Variant) = - KFiles.joinAndMakeDir(mergedResourcesNoVariant(project, variant), variant.toIntermediateDir()) + KFiles.joinAndMakeDir(mergedResourcesNoVariant(project), variant.toIntermediateDir()) } } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt index ab066f1f..0f720403 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt @@ -254,8 +254,6 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v // Call dx to generate classes.dex // val buildToolsDir = buildToolsVersion(project) - val dx = "${androidHome(project)}/build-tools/$buildToolsDir/dx" + - if (OperatingSystem.current().isWindows()) ".bat" else "" val classesDexDir = KFiles.joinDir(AndroidFiles.intermediates(project), "dex", context.variant.toIntermediateDir()) File(classesDexDir).mkdirs() @@ -388,12 +386,12 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v // IRunContributor override fun affinity(project: Project, context: KobaltContext): Int { - val manifest = AndroidFiles.manifest(project, context) + val manifest = AndroidFiles.manifest(project) return if (File(manifest).exists()) IAffinity.DEFAULT_POSITIVE_AFFINITY else 0 } override fun run(project: Project, context: KobaltContext, classpath: List): TaskResult { - val manifest = AndroidFiles.manifest(project, context) + val manifest = AndroidFiles.manifest(project) FileInputStream(File(manifest)).use { ins -> // adb shell am start -n com.package.name/com.package.name.ActivityName val manifest = AndroidManifest(ins) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/android/Merger.kt b/src/main/kotlin/com/beust/kobalt/plugin/android/Merger.kt index c585f4df..839c4a66 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/android/Merger.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/android/Merger.kt @@ -22,7 +22,7 @@ import javax.xml.bind.annotation.XmlValue */ class Merger @Inject constructor() { fun merge(project: Project, context: KobaltContext) { - File(AndroidFiles.mergedResourcesNoVariant(project, context.variant)).deleteRecursively() + File(AndroidFiles.mergedResourcesNoVariant(project)).deleteRecursively() mergeResources(project, context.variant) mergeAndroidManifest(project, context.variant) log(2, "All done merging") diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt index bc67a249..0e73f5d1 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -92,10 +92,12 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors, private fun runJarFile(project: Project, config: ApplicationConfig) : TaskResult { val jarName = project.projectProperties.get(PackagingPlugin.JAR_NAME) as String + @Suppress("UNCHECKED_CAST") val packages = project.projectProperties.get(PackagingPlugin.PACKAGES) as List val allDeps = arrayListOf(jarName) val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!! if (! isFatJar(packages, jarName)) { + @Suppress("UNCHECKED_CAST") val projDeps = project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS) as List // If the jar file is not fat, we need to add the transitive closure of all dependencies diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 7ce66f54..aa944b44 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -97,7 +97,7 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, */ private fun compilerFirst(list: List): List { val result = arrayListOf() - list.forEach { it + list.forEach { if (it.name.startsWith("kotlin-")) result.add(0, it) else result.add(it) } 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 99662089..52b039d9 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -11,7 +11,6 @@ import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.glob import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.maven.DependencyManager -import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors @@ -171,6 +170,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana log(2, "Creating fat jar") val seen = hashSetOf() + @Suppress("UNCHECKED_CAST") val dependentProjects = project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS) as List listOf(dependencyManager.calculateDependencies(project, context, dependentProjects, @@ -204,7 +204,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana true /* expandJarFiles */, jarFactory) } - private fun buildDir(project: Project) = KFiles.makeDir(project.directory, project.buildDirectory!!) + private fun buildDir(project: Project) = KFiles.makeDir(project.directory, project.buildDirectory) private fun findIncludedFiles(directory: String, files: List, excludes: List) : List { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 57f8333b..4dc696de 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -13,6 +13,7 @@ import java.io.File import javax.inject.Inject import javax.inject.Singleton +@Suppress("VARIABLE_WITH_REDUNDANT_INITIALIZER") @Singleton public class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGenerator.IFactory, val jcenterFactory: JCenterApi.IFactory, val github: GithubApi, val localProperties: LocalProperties) @@ -100,7 +101,7 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P // Upload to Maven // val trMaven = jcenter.uploadMaven(project, findArtifactFiles(project), configuration) - var success = trMaven.success + success = trMaven.success if (! success) messages.add(trMaven.errorMessage!!) // From f227ce969820bcd7f0421fb1b27ca0aa37679d86 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 1 Dec 2015 13:58:25 -0800 Subject: [PATCH 2/5] Fixes for the IDEA plug-in. --- .../kobalt/internal/build/BuildFileCompiler.kt | 14 ++------------ .../internal/remote/GetDependenciesCommand.kt | 8 ++------ 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt index 41ce498d..12dfa7b8 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt @@ -8,14 +8,12 @@ import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.PluginProperties import com.beust.kobalt.api.Project import com.beust.kobalt.internal.PluginInfo -import com.beust.kobalt.internal.build.VersionFile import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.log import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate import com.google.inject.assistedinject.Assisted -import rx.subjects.PublishSubject import java.io.File import java.net.URL import java.nio.file.Paths @@ -35,8 +33,6 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b fun create(@Assisted("buildFiles") buildFiles: List, pluginInfo: PluginInfo) : BuildFileCompiler } - val observable = PublishSubject.create>() - private val SCRIPT_JAR = "buildScript.jar" fun compileBuildFiles(args: Args): List { @@ -115,12 +111,6 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b * - the source code for the modified Build.kt (after profiles are applied) * - the URL's of all the plug-ins that were found. */ - private fun parseBuildFile(context: KobaltContext, buildFile: BuildFile) : ParsedBuildFile { - // Parse the build file so we can generate preBuildScript and buildScript from it. - with(ParsedBuildFile(buildFile, context, buildScriptUtil, dependencyManager, files)) { - // Notify possible listeners (e.g. KobaltServer) we now have all the projects - observable.onNext(projects) - return this - } - } + private fun parseBuildFile(context: KobaltContext, buildFile: BuildFile) = + ParsedBuildFile(buildFile, context, buildScriptUtil, dependencyManager, files) } diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt b/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt index 6dbb49d6..4c07493f 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt @@ -30,12 +30,8 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors, override fun run(sender: ICommandSender, received: JsonObject) { val buildFile = BuildFile(Paths.get(received.get("buildFile").asString), "GetDependenciesCommand") val scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo) - scriptCompiler.observable.subscribe { - projects -> if (projects.size > 0) { - sender.sendData(toData(projects)) - } - } - scriptCompiler.compileBuildFiles(args) + val projects = scriptCompiler.compileBuildFiles(args) + sender.sendData(toData(projects)) } private fun toData(projects: List) : CommandData { From b80bcaeda34095b0ab4db08c592ac18eaeee7c35 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 1 Dec 2015 13:58:39 -0800 Subject: [PATCH 3/5] 0.312. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index 12e3b2e3..36527fd1 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=0.311 \ No newline at end of file +kobalt.version=0.312 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 9056348b..186102e0 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=0.311 +kobalt.version=0.312 From cd4363640ef21a08f61e311aa3836cd74309bd0c Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 1 Dec 2015 14:48:56 -0800 Subject: [PATCH 4/5] Typo. --- src/main/kotlin/com/beust/kobalt/Args.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/Args.kt b/src/main/kotlin/com/beust/kobalt/Args.kt index 26491a07..bf1b44e8 100644 --- a/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/src/main/kotlin/com/beust/kobalt/Args.kt @@ -42,7 +42,7 @@ class Args { @Parameter(names = arrayOf("--port"), description = "Port, if --server was specified") var port: Int = DEFAULT_SERVER_PORT - @Parameter(names = arrayOf("--profiles"), description = "Comma-separate list of profiles to run") + @Parameter(names = arrayOf("--profiles"), description = "Comma-separated list of profiles to run") var profiles: String? = null @Parameter(names = arrayOf("--resolve"), description = "Resolve the given dependency and display its tree") From ec5a8bf69db9c9e0184b548e8ff97cb0d52528a3 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 1 Dec 2015 14:49:32 -0800 Subject: [PATCH 5/5] Exclude certificate files from META-INF. --- .../kotlin/com/beust/kobalt/misc/KFiles.kt | 32 ++++++++++++++++--- .../beust/kobalt/plugin/packaging/JarUtils.kt | 8 ++++- .../plugin/packaging/PackagingPlugin.kt | 26 ++------------- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 9bc2d03f..0cdad327 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.misc +import com.beust.kobalt.IFileSpec import com.beust.kobalt.SystemProperties import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Project @@ -7,10 +8,10 @@ import com.beust.kobalt.homeDir import com.beust.kobalt.internal.build.BuildFile import java.io.File import java.io.IOException -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths -import java.nio.file.StandardCopyOption +import java.nio.file.* +import kotlin.io.FileAlreadyExistsException +import kotlin.io.FileSystemException +import kotlin.io.NoSuchFileException class KFiles { val kobaltJar : String @@ -102,7 +103,7 @@ class KFiles { allDirs.addAll(directories.map { File(rootDir, it.path) }) } - val seen = hashSetOf() + val seen = hashSetOf() allDirs.forEach { dir -> if (! dir.exists()) { log(2, "Couldn't find directory $dir") @@ -248,6 +249,27 @@ class KFiles { fun makeOutputDir(project: Project) : File = makeDir(project, KFiles.CLASSES_DIR) fun makeOutputTestDir(project: Project) : File = makeDir(project, KFiles.TEST_CLASSES_DIR) + + fun isExcluded(file: File, excludes: List) = isExcluded(file.path, excludes) + + fun isExcluded(file: String, excludes: List) : Boolean { + if (excludes.isEmpty()) { + return false + } else { + val ex = arrayListOf() + excludes.forEach { + ex.add(FileSystems.getDefault().getPathMatcher("glob:${it.spec}")) + } + ex.forEach { + if (it.matches(Paths.get(file))) { + log(2, "Excluding $file") + return true + } + } + } + return false + } + } fun findRecursively(directory: File, function: Function1): List { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt index c83e2704..07403fd4 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt @@ -1,6 +1,7 @@ package com.beust.kobalt.plugin.packaging import com.beust.kobalt.IFileSpec +import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.log import com.google.common.io.CharStreams import java.io.* @@ -28,6 +29,11 @@ public class JarUtils { } } + private val DEFAULT_JAR_EXCLUDES = arrayListOf( + IFileSpec.Glob("META-INF/*.SF"), + IFileSpec.Glob("META-INF/*.DSA"), + IFileSpec.Glob("META-INF/*.RSA")) + public fun addSingleFile(directory: String, file: IncludedFile, outputStream: ZipOutputStream, expandJarFiles: Boolean, onError: (Exception) -> Unit = DEFAULT_HANDLER) { file.specs.forEach { spec -> @@ -56,7 +62,7 @@ public class JarUtils { val stream = JarInputStream(FileInputStream(source)) var entry = stream.nextEntry while (entry != null) { - if (!entry.isDirectory) { + if (! entry.isDirectory && ! KFiles.isExcluded(entry.name, DEFAULT_JAR_EXCLUDES)) { val ins = JarFile(source).getInputStream(entry) addEntry(ins, JarEntry(entry), outputStream, onError) } 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 52b039d9..fea87c77 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -20,8 +20,6 @@ import com.beust.kobalt.plugin.java.JavaPlugin import java.io.File import java.io.FileOutputStream import java.io.OutputStream -import java.nio.file.FileSystems -import java.nio.file.PathMatcher import java.nio.file.Paths import java.util.jar.JarOutputStream import java.util.zip.ZipOutputStream @@ -72,24 +70,6 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana return TaskResult() } - private fun isExcluded(file: File, excludes: List) : Boolean { - if (excludes.isEmpty()) { - return false - } else { - val ex = arrayListOf() - excludes.forEach { - ex.add(FileSystems.getDefault().getPathMatcher("glob:${it.spec}")) - } - ex.forEach { - if (it.matches(Paths.get(file.name))) { - log(2, "Excluding $file") - return true - } - } - } - return false - } - private fun generateWar(project: Project, war: War) : File { // // src/main/web app and classes @@ -153,7 +133,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana // Class files val files = KFiles.findRecursively(classesDir).map { File(relClassesDir.toFile(), it) } - val filesNotExcluded : List = files.filter { ! isExcluded(it, jar.excludes) } + val filesNotExcluded : List = files.filter { ! KFiles.isExcluded(it, jar.excludes) } val fileSpecs = arrayListOf() filesNotExcluded.forEach { fileSpecs.add(FileSpec(it.path.toString().substring(prefixPath.toString().length + 1))) @@ -183,7 +163,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana }.forEach { file : File -> if (! seen.contains(file.name)) { seen.add(file.name) - if (!isExcluded(file, jar.excludes)) { + if (! KFiles.isExcluded(file, jar.excludes)) { allFiles.add(IncludedFile(arrayListOf(FileSpec(file.path)))) } } @@ -221,7 +201,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } } - if (!isExcluded(file, excludes)) { + if (! KFiles.isExcluded(file, excludes)) { includedSpecs.add(FileSpec(file.path)) } else { log(2, "Not adding ${file.path} to jar file because it's excluded")