diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-03-15 01:05:28 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-03-15 01:05:28 +0000 |
commit | f410d39f9e6507e014ba0b1ceceaec598b6d5483 (patch) | |
tree | 216876fcf590f1cafc7bd635dc86e972521ed9d8 /tools/java/com/google/devtools/kotlin/SourceJarZipper.kt | |
parent | 24396154a980126e9bf614e866509d51a292cf0c (diff) | |
parent | e4697353d03a4a6d18e081c0cd8d7ed39bb25977 (diff) | |
download | bazelbuild-kotlin-rules-f410d39f9e6507e014ba0b1ceceaec598b6d5483.tar.gz |
Snap for 9746098 from e4697353d03a4a6d18e081c0cd8d7ed39bb25977 to udc-d1-releaseandroid-14.0.0_r9android-14.0.0_r8android-14.0.0_r7android-14.0.0_r6android-14.0.0_r5android-14.0.0_r4android-14.0.0_r3android-14.0.0_r12android-14.0.0_r11android-14.0.0_r10android14-d1-s7-releaseandroid14-d1-s6-releaseandroid14-d1-s5-releaseandroid14-d1-s4-releaseandroid14-d1-s3-releaseandroid14-d1-s2-releaseandroid14-d1-s1-releaseandroid14-d1-release
Change-Id: I800c5671f61564f3492fa6de16219bdcdcb97c46
Diffstat (limited to 'tools/java/com/google/devtools/kotlin/SourceJarZipper.kt')
-rw-r--r-- | tools/java/com/google/devtools/kotlin/SourceJarZipper.kt | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/tools/java/com/google/devtools/kotlin/SourceJarZipper.kt b/tools/java/com/google/devtools/kotlin/SourceJarZipper.kt index ac57efe..c2d34d8 100644 --- a/tools/java/com/google/devtools/kotlin/SourceJarZipper.kt +++ b/tools/java/com/google/devtools/kotlin/SourceJarZipper.kt @@ -52,15 +52,16 @@ fun main(args: Array<String>) { } /** - * Checks for duplicates and add an entry into [errors] if found any, otherwise adds a pair - * of [zipPath] and [sourcePath] to the receiver - * @receiver a mutable map of path to path, where keys are relative paths of files inside the - * resulting .jar, and values are full paths of files - * @param[zipPath] relative path inside the jar, built either from package name - * (e.g. package com.google.foo -> com/google/foo/FileName.kt) or by resolving the file name - * relatively the directory it came from (e.g. foo/bar/1/2.txt came from foo/bar -> 1/2.txt) + * Checks for duplicates and adds an entry into [errors] if one is found, otherwise adds a pair of + * [zipPath] and [sourcePath] to the receiver + * + * @param[zipPath] relative path inside the jar, built either from package name (e.g. package + * com.google.foo -> com/google/foo/FileName.kt) or by resolving the file name relative to the + * directory it came from (e.g. foo/bar/1/2.txt came from foo/bar -> 1/2.txt) * @param[sourcePath] full path of file into its file system * @param[errors] list of strings describing catched errors + * @receiver a mutable map of path to path, where keys are relative paths of files inside the + * resulting .jar, and values are full paths of files */ fun MutableMap<Path, Path>.checkForDuplicatesAndSetFilePathToPathInsideJar( zipPath: Path, @@ -78,6 +79,12 @@ fun MutableMap<Path, Path>.checkForDuplicatesAndSetFilePathToPathInsideJar( } } +private fun clearSingletonEmptyPath(list: MutableList<Path>) { + if (list.size == 1 && list[0].toString() == "") { + list.clear() + } +} + fun MutableMap<Path, Path>.writeToStream( zipper: ZipOutputStream, prefix: String = "", @@ -124,9 +131,8 @@ class Zip : Runnable { } override fun run() { - check(kotlinSrcs.isNotEmpty() or commonSrcs.isNotEmpty()) { - "Expected at least one source file." - } + clearSingletonEmptyPath(kotlinSrcs) + clearSingletonEmptyPath(commonSrcs) // Validating files and getting paths for resulting .jar in one cycle // for each _srcs list @@ -188,9 +194,6 @@ class Zip : Runnable { } } - if (ktZipPathToSourcePath.isEmpty() && commonZipPathToSourcePath.isEmpty()) { - errors.add("Expected at least one valid source file .kt or .java") - } check(errors.isEmpty()) { errors.joinToString("\n") } ZipOutputStream(BufferedOutputStream(Files.newOutputStream(outputJar))).use { zipper -> @@ -243,6 +246,8 @@ class ZipResources : Runnable { val inputDirs = mutableListOf<Path>() override fun run() { + clearSingletonEmptyPath(inputDirs) + val filePathToOutputPath = mutableMapOf<Path, Path>() val errors = mutableListOf<String>() |