Reformat K2JSDce.kt
This commit is contained in:
@@ -38,8 +38,7 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
val files = collectInputFiles(baseDir, arg, messageCollector)
|
||||
if (files != null) {
|
||||
files
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
hasErrors = true
|
||||
emptyList()
|
||||
}
|
||||
@@ -56,8 +55,9 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
for (file in files) {
|
||||
existingFiles[file.outputPath]?.let {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR,
|
||||
"duplicate target file will be created for '${file.resource.name}' and '${it.resource.name}'")
|
||||
CompilerMessageSeverity.ERROR,
|
||||
"duplicate target file will be created for '${file.resource.name}' and '${it.resource.name}'"
|
||||
)
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
}
|
||||
existingFiles[file.outputPath] = file
|
||||
@@ -69,8 +69,7 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
|
||||
return if (!arguments.devMode) {
|
||||
performDce(files, arguments, messageCollector)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
copyFiles(files)
|
||||
ExitCode.OK
|
||||
}
|
||||
@@ -95,8 +94,10 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
val reachabilitySeverity = if (arguments.printReachabilityInfo) CompilerMessageSeverity.INFO else CompilerMessageSeverity.LOGGING
|
||||
messageCollector.report(reachabilitySeverity, "")
|
||||
for (node in nodes.extractRoots()) {
|
||||
printTree(node, { messageCollector.report(reachabilitySeverity, it) },
|
||||
printNestedMembers = false, showLocations = true)
|
||||
printTree(
|
||||
node, { messageCollector.report(reachabilitySeverity, it) },
|
||||
printNestedMembers = false, showLocations = true
|
||||
)
|
||||
}
|
||||
|
||||
return ExitCode.OK
|
||||
@@ -123,14 +124,13 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
FileOutputStream(targetFile).use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun mapSourcePaths(inputFile: File, targetFile: File): Boolean {
|
||||
val json = try {
|
||||
InputStreamReader(FileInputStream(inputFile), "UTF-8").use { parseJson(it) }
|
||||
}
|
||||
catch (e: JsonSyntaxException) {
|
||||
} catch (e: JsonSyntaxException) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -145,12 +145,10 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
if (result != null) {
|
||||
if (File(targetFile.parentFile, result).exists()) {
|
||||
result
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
@@ -180,8 +178,10 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
collectInputFilesFromZip(baseDir, fileName)
|
||||
}
|
||||
else -> {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"invalid file name '$fileName'; must end either with '.js', '.zip' or '.jar'")
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR,
|
||||
"invalid file name '$fileName'; must end either with '.js', '.zip' or '.jar'"
|
||||
)
|
||||
null
|
||||
}
|
||||
}
|
||||
@@ -197,41 +197,47 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
val moduleName = getModuleNameFromPath(path)
|
||||
val pathToSourceMapCandidate = "$path.map"
|
||||
val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null
|
||||
return InputFile(InputResource.file(path), pathToSourceMap?.let { InputResource.file(it) },
|
||||
File(baseDir, "$moduleName.js").absolutePath, moduleName)
|
||||
return InputFile(
|
||||
InputResource.file(path), pathToSourceMap?.let { InputResource.file(it) },
|
||||
File(baseDir, "$moduleName.js").absolutePath, moduleName
|
||||
)
|
||||
}
|
||||
|
||||
private fun collectInputFilesFromZip(baseDir: File, path: String): List<InputFile> {
|
||||
return ZipFile(path).use { zipFile ->
|
||||
zipFile.entries().asSequence()
|
||||
.filter { !it.isDirectory }
|
||||
.filter { it.name.endsWith(".js") }
|
||||
.filter { zipFile.getEntry(it.name.metaJs()) != null }
|
||||
.distinctBy { it.name }
|
||||
.map { entry ->
|
||||
val moduleName = getModuleNameFromPath(entry.name)
|
||||
val pathToSourceMapCandidate = "${entry.name}.map"
|
||||
val pathToSourceMap = if (zipFile.getEntry(pathToSourceMapCandidate) != null) pathToSourceMapCandidate else null
|
||||
InputFile(InputResource.zipFile(path, entry.name), pathToSourceMap?.let { InputResource.zipFile(path, it) },
|
||||
File(baseDir, "$moduleName.js").absolutePath, moduleName)
|
||||
}
|
||||
.toList()
|
||||
.filter { !it.isDirectory }
|
||||
.filter { it.name.endsWith(".js") }
|
||||
.filter { zipFile.getEntry(it.name.metaJs()) != null }
|
||||
.distinctBy { it.name }
|
||||
.map { entry ->
|
||||
val moduleName = getModuleNameFromPath(entry.name)
|
||||
val pathToSourceMapCandidate = "${entry.name}.map"
|
||||
val pathToSourceMap = if (zipFile.getEntry(pathToSourceMapCandidate) != null) pathToSourceMapCandidate else null
|
||||
InputFile(
|
||||
InputResource.zipFile(path, entry.name), pathToSourceMap?.let { InputResource.zipFile(path, it) },
|
||||
File(baseDir, "$moduleName.js").absolutePath, moduleName
|
||||
)
|
||||
}
|
||||
.toList()
|
||||
}
|
||||
}
|
||||
|
||||
private fun collectInputFilesFromDirectory(baseDir: File, path: String): List<InputFile> {
|
||||
return File(path).walkTopDown().asSequence()
|
||||
.filter { !it.isDirectory }
|
||||
.filter { it.name.endsWith(".js") }
|
||||
.filter { File(it.path.metaJs()).exists() }
|
||||
.map { entry ->
|
||||
val moduleName = getModuleNameFromPath(entry.name)
|
||||
val pathToSourceMapCandidate = "${entry.path}.map"
|
||||
val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null
|
||||
InputFile(InputResource.file(entry.path), pathToSourceMap?.let { InputResource.file(it) },
|
||||
File(baseDir, "$moduleName.js").absolutePath, moduleName)
|
||||
}
|
||||
.toList()
|
||||
.filter { !it.isDirectory }
|
||||
.filter { it.name.endsWith(".js") }
|
||||
.filter { File(it.path.metaJs()).exists() }
|
||||
.map { entry ->
|
||||
val moduleName = getModuleNameFromPath(entry.name)
|
||||
val pathToSourceMapCandidate = "${entry.path}.map"
|
||||
val pathToSourceMap = if (File(pathToSourceMapCandidate).exists()) pathToSourceMapCandidate else null
|
||||
InputFile(
|
||||
InputResource.file(entry.path), pathToSourceMap?.let { InputResource.file(it) },
|
||||
File(baseDir, "$moduleName.js").absolutePath, moduleName
|
||||
)
|
||||
}
|
||||
.toList()
|
||||
}
|
||||
|
||||
private fun String.metaJs() = removeSuffix(".js") + ".meta.js"
|
||||
|
||||
Reference in New Issue
Block a user