aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Utilities
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-07-17 16:36:09 +0200
committerPaweł Marks <pmarks@virtuslab.com>2020-07-17 16:36:09 +0200
commit6996b1135f61c7d2cb60b0652c6a2691dda31990 (patch)
treed568096c25e31c28d14d518a63458b5a7526b896 /core/src/main/kotlin/Utilities
parentde56cab76f556e5b4af0b8c8cb08d8b482b86d0a (diff)
parent1c3530dcbb50c347f80bef694829dbefe89eca77 (diff)
downloaddokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.gz
dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.bz2
dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.zip
Merge branch 'dev-0.11.0'
Diffstat (limited to 'core/src/main/kotlin/Utilities')
-rw-r--r--core/src/main/kotlin/Utilities/DokkaLogging.kt27
-rw-r--r--core/src/main/kotlin/Utilities/DokkaModules.kt85
-rw-r--r--core/src/main/kotlin/Utilities/Html.kt12
-rw-r--r--core/src/main/kotlin/Utilities/Links.kt18
-rw-r--r--core/src/main/kotlin/Utilities/Path.kt5
-rw-r--r--core/src/main/kotlin/Utilities/ServiceLocator.kt97
-rw-r--r--core/src/main/kotlin/Utilities/Uri.kt40
7 files changed, 0 insertions, 284 deletions
diff --git a/core/src/main/kotlin/Utilities/DokkaLogging.kt b/core/src/main/kotlin/Utilities/DokkaLogging.kt
deleted file mode 100644
index 1ef52837..00000000
--- a/core/src/main/kotlin/Utilities/DokkaLogging.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.jetbrains.dokka
-
-interface DokkaLogger {
- fun info(message: String)
- fun warn(message: String)
- fun error(message: String)
-}
-
-object DokkaConsoleLogger : DokkaLogger {
- var warningCount: Int = 0
-
- override fun info(message: String) = println(message)
- override fun warn(message: String) {
- println("WARN: $message")
- warningCount++
- }
-
- override fun error(message: String) = println("ERROR: $message")
-
- fun report() {
- if (warningCount > 0) {
- println("generation completed with $warningCount warnings")
- } else {
- println("generation completed successfully")
- }
- }
-}
diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt
deleted file mode 100644
index 919ec30f..00000000
--- a/core/src/main/kotlin/Utilities/DokkaModules.kt
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.jetbrains.dokka.Utilities
-
-import com.google.inject.Binder
-import com.google.inject.Module
-import com.google.inject.TypeLiteral
-import com.google.inject.binder.AnnotatedBindingBuilder
-import com.google.inject.name.Names
-import org.jetbrains.dokka.*
-import org.jetbrains.dokka.Formats.FormatDescriptor
-import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
-import java.io.File
-import kotlin.reflect.KClass
-
-const val impliedPlatformsName = "impliedPlatforms"
-
-class DokkaRunModule(val configuration: DokkaConfiguration) : Module {
- override fun configure(binder: Binder) {
- binder.bind<DokkaConfiguration>().toInstance(configuration)
- binder.bind(StringListType).annotatedWith(Names.named(impliedPlatformsName)).toInstance(configuration.impliedPlatforms)
-
- binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(configuration.outputDir))
- }
-
-}
-
-class DokkaAnalysisModule(val environment: AnalysisEnvironment,
- val configuration: DokkaConfiguration,
- val defaultPlatformsProvider: DefaultPlatformsProvider,
- val nodeReferenceGraph: NodeReferenceGraph,
- val passConfiguration: DokkaConfiguration.PassConfiguration,
- val logger: DokkaLogger) : Module {
- override fun configure(binder: Binder) {
- binder.bind<DokkaLogger>().toInstance(logger)
-
- val coreEnvironment = environment.createCoreEnvironment()
- binder.bind<KotlinCoreEnvironment>().toInstance(coreEnvironment)
-
- val (dokkaResolutionFacade, libraryResolutionFacade) = environment.createResolutionFacade(coreEnvironment)
- binder.bind<DokkaResolutionFacade>().toInstance(dokkaResolutionFacade)
- binder.bind<DokkaResolutionFacade>().annotatedWith(Names.named("libraryResolutionFacade")).toInstance(libraryResolutionFacade)
-
- binder.bind<DokkaConfiguration.PassConfiguration>().toInstance(passConfiguration)
-
- binder.bind<DefaultPlatformsProvider>().toInstance(defaultPlatformsProvider)
-
- binder.bind<NodeReferenceGraph>().toInstance(nodeReferenceGraph)
-
- val descriptor = ServiceLocator.lookup<FormatDescriptor>("format", configuration.format)
- descriptor.configureAnalysis(binder)
- }
-}
-
-object StringListType : TypeLiteral<@JvmSuppressWildcards List<String>>()
-
-class DokkaOutputModule(val configuration: DokkaConfiguration,
- val logger: DokkaLogger) : Module {
- override fun configure(binder: Binder) {
- binder.bind<DokkaLogger>().toInstance(logger)
-
- val descriptor = ServiceLocator.lookup<FormatDescriptor>("format", configuration.format)
-
- descriptor.configureOutput(binder)
- }
-}
-
-private inline fun <reified T: Any> Binder.registerCategory(category: String) {
- ServiceLocator.allServices(category).forEach {
- @Suppress("UNCHECKED_CAST")
- bind(T::class.java).annotatedWith(Names.named(it.name)).to(T::class.java.classLoader.loadClass(it.className) as Class<T>)
- }
-}
-
-private inline fun <reified Base : Any, reified T : Base> Binder.bindNameAnnotated(name: String) {
- bind(Base::class.java).annotatedWith(Names.named(name)).to(T::class.java)
-}
-
-
-inline fun <reified T: Any> Binder.bind(): AnnotatedBindingBuilder<T> = bind(T::class.java)
-
-inline fun <reified T: Any> Binder.lazyBind(): Lazy<AnnotatedBindingBuilder<T>> = lazy { bind(T::class.java) }
-
-inline infix fun <reified T: Any, TKClass: KClass<out T>> Lazy<AnnotatedBindingBuilder<T>>.toOptional(kClass: TKClass?) =
- kClass?.let { value toType it }
-
-inline infix fun <reified T: Any, TKClass: KClass<out T>> AnnotatedBindingBuilder<T>.toType(kClass: TKClass) = to(kClass.java)
diff --git a/core/src/main/kotlin/Utilities/Html.kt b/core/src/main/kotlin/Utilities/Html.kt
deleted file mode 100644
index de1ce1a5..00000000
--- a/core/src/main/kotlin/Utilities/Html.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.jetbrains.dokka
-
-import java.net.URLEncoder
-
-
-/**
- * Replaces symbols reserved in HTML with their respective entities.
- * Replaces & with &amp;, < with &lt; and > with &gt;
- */
-fun String.htmlEscape(): String = replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
-
-fun String.urlEncoded(): String = URLEncoder.encode(this, "UTF-8") \ No newline at end of file
diff --git a/core/src/main/kotlin/Utilities/Links.kt b/core/src/main/kotlin/Utilities/Links.kt
deleted file mode 100644
index 34423e4e..00000000
--- a/core/src/main/kotlin/Utilities/Links.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.jetbrains.dokka.Utilities
-
-import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.ExternalDocumentationLinkImpl
-
-fun DokkaConfiguration.PassConfiguration.defaultLinks(): List<ExternalDocumentationLinkImpl> {
- val links = mutableListOf<ExternalDocumentationLinkImpl>()
- if (!noJdkLink)
- links += DokkaConfiguration.ExternalDocumentationLink
- .Builder("https://docs.oracle.com/javase/${jdkVersion}/docs/api/")
- .build() as ExternalDocumentationLinkImpl
-
- if (!noStdlibLink)
- links += DokkaConfiguration.ExternalDocumentationLink
- .Builder("https://kotlinlang.org/api/latest/jvm/stdlib/")
- .build() as ExternalDocumentationLinkImpl
- return links
-}
diff --git a/core/src/main/kotlin/Utilities/Path.kt b/core/src/main/kotlin/Utilities/Path.kt
deleted file mode 100644
index 05838499..00000000
--- a/core/src/main/kotlin/Utilities/Path.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.jetbrains.dokka
-
-import java.io.File
-
-fun File.appendExtension(extension: String) = if (extension.isEmpty()) this else File(path + "." + extension)
diff --git a/core/src/main/kotlin/Utilities/ServiceLocator.kt b/core/src/main/kotlin/Utilities/ServiceLocator.kt
deleted file mode 100644
index eda83422..00000000
--- a/core/src/main/kotlin/Utilities/ServiceLocator.kt
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.jetbrains.dokka.Utilities
-
-import java.io.File
-import java.net.URISyntaxException
-import java.net.URL
-import java.util.*
-import java.util.jar.JarFile
-import java.util.zip.ZipEntry
-
-data class ServiceDescriptor(val name: String, val category: String, val description: String?, val className: String)
-
-class ServiceLookupException(message: String) : Exception(message)
-
-object ServiceLocator {
- fun <T : Any> lookup(clazz: Class<T>, category: String, implementationName: String): T {
- val descriptor = lookupDescriptor(category, implementationName)
- return lookup(clazz, descriptor)
- }
-
- fun <T : Any> lookup(
- clazz: Class<T>,
- descriptor: ServiceDescriptor
- ): T {
- val loadedClass = javaClass.classLoader.loadClass(descriptor.className)
- val constructor = loadedClass.constructors.firstOrNull { it.parameterTypes.isEmpty() } ?: throw ServiceLookupException("Class ${descriptor.className} has no corresponding constructor")
-
- val implementationRawType: Any =
- if (constructor.parameterTypes.isEmpty()) constructor.newInstance() else constructor.newInstance(constructor)
-
- if (!clazz.isInstance(implementationRawType)) {
- throw ServiceLookupException("Class ${descriptor.className} is not a subtype of ${clazz.name}")
- }
-
- @Suppress("UNCHECKED_CAST")
- return implementationRawType as T
- }
-
- private fun lookupDescriptor(category: String, implementationName: String): ServiceDescriptor {
- val properties = javaClass.classLoader.getResourceAsStream("dokka/$category/$implementationName.properties")?.use { stream ->
- Properties().let { properties ->
- properties.load(stream)
- properties
- }
- } ?: throw ServiceLookupException("No implementation with name $implementationName found in category $category")
-
- val className = properties["class"]?.toString() ?: throw ServiceLookupException("Implementation $implementationName has no class configured")
-
- return ServiceDescriptor(implementationName, category, properties["description"]?.toString(), className)
- }
-
- fun URL.toFile(): File {
- assert(protocol == "file")
-
- return try {
- File(toURI())
- } catch (e: URISyntaxException) { //Try to handle broken URLs, with unescaped spaces
- File(path)
- }
- }
-
- fun allServices(category: String): List<ServiceDescriptor> {
- val entries = this.javaClass.classLoader.getResources("dokka/$category")?.toList() ?: emptyList()
-
- return entries.flatMap {
- when (it.protocol) {
- "file" -> it.toFile().listFiles()?.filter { it.extension == "properties" }?.map { lookupDescriptor(category, it.nameWithoutExtension) } ?: emptyList()
- "jar" -> {
- val file = JarFile(URL(it.file.substringBefore("!")).toFile())
- try {
- val jarPath = it.file.substringAfterLast("!").removePrefix("/").removeSuffix("/")
- file.entries()
- .asSequence()
- .filter { entry -> !entry.isDirectory && entry.path == jarPath && entry.extension == "properties" }
- .map { entry ->
- lookupDescriptor(category, entry.fileName.substringBeforeLast("."))
- }.toList()
- } finally {
- file.close()
- }
- }
- else -> emptyList<ServiceDescriptor>()
- }
- }
- }
-}
-
-inline fun <reified T : Any> ServiceLocator.lookup(category: String, implementationName: String): T = lookup(T::class.java, category, implementationName)
-inline fun <reified T : Any> ServiceLocator.lookup(desc: ServiceDescriptor): T = lookup(T::class.java, desc)
-
-private val ZipEntry.fileName: String
- get() = name.substringAfterLast("/", name)
-
-private val ZipEntry.path: String
- get() = name.substringBeforeLast("/", "").removePrefix("/")
-
-private val ZipEntry.extension: String?
- get() = fileName.let { fn -> if ("." in fn) fn.substringAfterLast(".") else null }
diff --git a/core/src/main/kotlin/Utilities/Uri.kt b/core/src/main/kotlin/Utilities/Uri.kt
deleted file mode 100644
index 9827c624..00000000
--- a/core/src/main/kotlin/Utilities/Uri.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.jetbrains.dokka
-
-import java.net.URI
-
-
-fun URI.relativeTo(uri: URI): URI {
- // Normalize paths to remove . and .. segments
- val base = uri.normalize()
- val child = this.normalize()
-
- fun StringBuilder.appendRelativePath() {
- // Split paths into segments
- var bParts = base.path.split('/').dropLastWhile { it.isEmpty() }
- val cParts = child.path.split('/').dropLastWhile { it.isEmpty() }
-
- // Discard trailing segment of base path
- if (bParts.isNotEmpty() && !base.path.endsWith("/")) {
- bParts = bParts.dropLast(1)
- }
-
- // Compute common prefix
- val commonPartsSize = bParts.zip(cParts).takeWhile { (basePart, childPart) -> basePart == childPart }.count()
- bParts.drop(commonPartsSize).joinTo(this, separator = "") { "../" }
- cParts.drop(commonPartsSize).joinTo(this, separator = "/")
- }
-
- return URI.create(buildString {
- if (base.path != child.path) {
- appendRelativePath()
- }
- child.rawQuery?.let {
- append("?")
- append(it)
- }
- child.rawFragment?.let {
- append("#")
- append(it)
- }
- })
-} \ No newline at end of file