diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-02-17 12:35:15 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-02-18 13:28:23 +0100 |
commit | a89d9a8c87cbe81bdba25b660d1b1fda1d0ce8ec (patch) | |
tree | 8e55f99386415fe644c6223a53825cf12022f8db /core/src/main/kotlin/renderers | |
parent | ba769f0695aaa9719b62ca32028fd3d24442f5ec (diff) | |
download | dokka-a89d9a8c87cbe81bdba25b660d1b1fda1d0ce8ec.tar.gz dokka-a89d9a8c87cbe81bdba25b660d1b1fda1d0ce8ec.tar.bz2 dokka-a89d9a8c87cbe81bdba25b660d1b1fda1d0ce8ec.zip |
Moves location providers and output writers to base plugin
Diffstat (limited to 'core/src/main/kotlin/renderers')
-rw-r--r-- | core/src/main/kotlin/renderers/FileWriter.kt | 78 | ||||
-rw-r--r-- | core/src/main/kotlin/renderers/OutputWriter.kt | 7 |
2 files changed, 0 insertions, 85 deletions
diff --git a/core/src/main/kotlin/renderers/FileWriter.kt b/core/src/main/kotlin/renderers/FileWriter.kt deleted file mode 100644 index 727a8d21..00000000 --- a/core/src/main/kotlin/renderers/FileWriter.kt +++ /dev/null @@ -1,78 +0,0 @@ -package org.jetbrains.dokka.renderers - -import org.jetbrains.dokka.plugability.DokkaContext -import java.io.File -import java.io.IOException -import java.net.URI -import java.nio.file.* - -class FileWriter(val context: DokkaContext): OutputWriter { - private val createdFiles: MutableSet<String> = mutableSetOf() - private val jarUriPrefix = "jar:file:" - private val root = context.configuration.outputDir - - override fun write(path: String, text: String, ext: String) { - if (createdFiles.contains(path)) { - context.logger.error("An attempt to write ${root}/$path several times!") - return - } - createdFiles.add(path) - - try { - val dir = Paths.get(root, path.dropLastWhile { it != '/' }).toFile() - dir.mkdirsOrFail() - Files.write(Paths.get(root, "$path$ext"), text.lines()) - } catch (e: Throwable) { - context.logger.error("Failed to write $this. ${e.message}") - e.printStackTrace() - } - } - - override fun writeResources(pathFrom: String, pathTo: String) = - if (javaClass.getResource(pathFrom).toURI().toString().startsWith(jarUriPrefix)) { - copyFromJar(pathFrom, pathTo) - } else { - copyFromDirectory(pathFrom, pathTo) - } - - - private fun copyFromDirectory(pathFrom: String, pathTo: String) { - val dest = Paths.get(root, pathTo).toFile() - val uri = javaClass.getResource(pathFrom).toURI() - File(uri).copyRecursively(dest, true) - } - - private fun copyFromJar(pathFrom: String, pathTo: String) { - val rebase = fun(path: String) = - "$pathTo/${path.removePrefix(pathFrom)}" - val dest = Paths.get(root, pathTo).toFile() - dest.mkdirsOrFail() - val uri = javaClass.getResource(pathFrom).toURI() - val fs = getFileSystemForURI(uri) - val path = fs.getPath(pathFrom) - for (file in Files.walk(path).iterator()) { - if (Files.isDirectory(file)) { - val dirPath = file.toAbsolutePath().toString() - Paths.get(root, rebase(dirPath)).toFile().mkdirsOrFail() - } else { - val filePath = file.toAbsolutePath().toString() - Paths.get(root, rebase(filePath)).toFile().writeBytes( - javaClass.getResourceAsStream(filePath).readBytes() - ) - } - } - } - - private fun File.mkdirsOrFail() { - if (!mkdirs() && !exists()) { - throw IOException("Failed to create directory $this") - } - } - - private fun getFileSystemForURI(uri: URI): FileSystem = - try { - FileSystems.newFileSystem(uri, emptyMap<String, Any>()) - } catch (e: FileSystemAlreadyExistsException) { - FileSystems.getFileSystem(uri) - } -}
\ No newline at end of file diff --git a/core/src/main/kotlin/renderers/OutputWriter.kt b/core/src/main/kotlin/renderers/OutputWriter.kt deleted file mode 100644 index e317f8ef..00000000 --- a/core/src/main/kotlin/renderers/OutputWriter.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.jetbrains.dokka.renderers - -interface OutputWriter { - - fun write(path: String, text: String, ext: String) - fun writeResources(pathFrom: String, pathTo: String) -}
\ No newline at end of file |