From 57182cf748fd3fb023c398eb48240dde5b3d78cb Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sat, 2 Dec 2023 01:48:07 +0000 Subject: [PATCH] javadoc --- build.gradle.kts | 9 +++++++++ src/main/kotlin/tinyvm/Commit.kt | 24 ++++++++++++++++-------- src/main/kotlin/tinyvm/Extensions.kt | 5 ----- src/main/kotlin/tinyvm/Tree.kt | 9 +++++++++ 4 files changed, 34 insertions(+), 13 deletions(-) delete mode 100644 src/main/kotlin/tinyvm/Extensions.kt diff --git a/build.gradle.kts b/build.gradle.kts index 87d286d..1acd6c3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ plugins { kotlin("jvm") version "1.9.21" id("org.jmailen.kotlinter") version "4.1.0" + id("org.jetbrains.dokka") version "1.9.10" `maven-publish` } @@ -23,10 +24,18 @@ kotlin { jvmToolchain(17) } +val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class) +val javadocJar: TaskProvider by tasks.registering(Jar::class) { + dependsOn(dokkaHtml) + archiveClassifier.set("javadoc") + from(dokkaHtml.outputDirectory) +} + publishing { publications.register("gpr") { artifactId = "tinyvm" from(components["java"]) + artifact(javadocJar) pom { name.set("TeamCity support for Gitea - Test Task - tiny version manager") description.set("This is a small project to implement a subset of git's functionality in Kotlin and was " + diff --git a/src/main/kotlin/tinyvm/Commit.kt b/src/main/kotlin/tinyvm/Commit.kt index bc8cab7..6f2f9d4 100644 --- a/src/main/kotlin/tinyvm/Commit.kt +++ b/src/main/kotlin/tinyvm/Commit.kt @@ -2,28 +2,36 @@ package tinyvm import java.security.MessageDigest import java.time.Instant +import java.util.HexFormat -abstract class Object( - val type: String, -) { +/** + * Represents an arbitrary version manager object. + */ +abstract class Object(val type: String) { abstract val data: String fun hash(): String = - MessageDigest - .getInstance("SHA-1") - .digest("$type ${data.length}\u0000$data".toByteArray()) - .toHex() + HexFormat.of().formatHex( + MessageDigest + .getInstance("SHA-1") + .digest("$type ${data.length}\u0000$data".toByteArray()), + ) } +/** + * Commits are a pointer to a 'head' tree with some metadata. + */ class Commit( val tree: Tree, val author: Author, val message: String, val timestamp: Instant, ) : Object("commit") { - // Use \n\n for end of header in-case additional metadata is implemented in the future. override val data: String + // Use \n\n for end of header in-case additional metadata is implemented in the future. get() = "tree ${tree.hash()}\nauthor $author\ntimestamp ${timestamp.epochSecond}\n\n$message" + + override fun toString(): String = "commit ${hash()}\n$data" } data class Author( diff --git a/src/main/kotlin/tinyvm/Extensions.kt b/src/main/kotlin/tinyvm/Extensions.kt deleted file mode 100644 index b08f3db..0000000 --- a/src/main/kotlin/tinyvm/Extensions.kt +++ /dev/null @@ -1,5 +0,0 @@ -package tinyvm - -import java.util.HexFormat - -fun ByteArray.toHex(): String = HexFormat.of().formatHex(this) \ No newline at end of file diff --git a/src/main/kotlin/tinyvm/Tree.kt b/src/main/kotlin/tinyvm/Tree.kt index 6025dfa..1500f48 100644 --- a/src/main/kotlin/tinyvm/Tree.kt +++ b/src/main/kotlin/tinyvm/Tree.kt @@ -1,7 +1,13 @@ package tinyvm +/** + * Tree nodes are either trees or blobs, represented by this sealed class. + */ sealed class Node(type: String) : Object(type) +/** + * A tree is a set of named nodes. + */ class Tree(val nodes: Map) : Node("tree") { // For simplicity just use the hex-formatted hash, not the actual value like git does. override val data: String @@ -11,4 +17,7 @@ class Tree(val nodes: Map) : Node("tree") { }.sorted().joinToString() } +/** + * A blob is a data container. + */ class Blob(override val data: String) : Node("blob") \ No newline at end of file