Skip to content

Commit 0061eea

Browse files
author
ADMSK\AVROGAL1
committed
docs: updates on documentation
Added informational and corporate documentation
1 parent 9c5c45c commit 0061eea

File tree

12 files changed

+618
-9
lines changed

12 files changed

+618
-9
lines changed

.github/workflows/release-changelog.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
tags:
66
- '*'
77

8+
jobs:
89
release:
910
if: startsWith(github.ref, 'refs/tags/')
1011
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
![GitHub Repository branches](https://badgen.net/github/branches/AlexRogalskiy/gradle-kotlin-sample)
2121
![GitHub Repository dependents](https://badgen.net/github/dependents-repo/AlexRogalskiy/gradle-kotlin-sample)
2222

23-
[![dependencies Status](https://status.david-dm.org/gh/AlexRogalskiy/gradle-kotlin-sample.svg)](https://david-dm.org/AlexRogalskiy/gradle-kotlin-sample)
24-
[![devDependencies Status](https://status.david-dm.org/gh/AlexRogalskiy/gradle-kotlin-sample.svg)](https://david-dm.org/AlexRogalskiy/gradle-kotlin-sample?type=dev)
25-
2623
## 🎹 _Table of contents_
2724

2825
<!-- toc -->
2926
- [☝ Getting Started](#-getting-started)
3027
- [👉 Development](#-development)
3128
- [📝 Versioning](#-versioning)
29+
- [🐛 Issues](#-issues)
3230
- [🌹 Authors](#-authors)
3331
- [💕 Contributing](#-contributing)
3432
- [🚨 Visitor stats](#-visitor-stats)

buildSrc/src/main/kotlin/plugins/spotless.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ configure<SpotlessExtension> {
9696
rootProject.file("spotless/copyright.java"),
9797
"^(package|object|import|interface|@file|//startfile)"
9898
)
99+
googleJavaFormat()
99100
removeUnusedImports()
100101
trimTrailingWhitespace()
101102
indentWithSpaces()

buildSrc/src/main/kotlin/tasks/common-tasks.gradle.kts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
*/
1616
package tasks
1717

18+
import extensions.createKotlinMainSources
19+
import extensions.createKotlinTestSources
1820
import extensions.shouldTreatCompilerWarningsAsErrors
1921
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2022
import org.gradle.api.tasks.testing.logging.TestLogEvent
2123
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2224
import utils.javaVersion
2325
import utils.kotlinVersion
2426
import utils.parallelForks
25-
import extensions.createKotlinMainSources
26-
import extensions.createKotlinTestSources
2727

2828
plugins {
2929
id("org.jetbrains.kotlin.jvm") apply false
@@ -134,8 +134,9 @@ tasks {
134134
jvmTarget = javaVersion.toString()
135135
apiVersion = kotlinVersion.toString()
136136
languageVersion = kotlinVersion.toString()
137+
allWarningsAsErrors = project.shouldTreatCompilerWarningsAsErrors()
137138

138-
kotlinOptions.freeCompilerArgs = listOf(
139+
freeCompilerArgs = listOf(
139140
"-progressive",
140141
"-Xuse-ir",
141142
"-Xjvm-default=enable",
@@ -148,7 +149,6 @@ tasks {
148149
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
149150
"-Xinline-classes"
150151
)
151-
kotlinOptions.allWarningsAsErrors = project.shouldTreatCompilerWarningsAsErrors()
152152
}
153153
}
154154

@@ -249,4 +249,28 @@ tasks {
249249
delete(File("buildSrc\\build"))
250250
// delete(rootProject.buildDir)
251251
}
252+
253+
val packageFat by creating(Zip::class) {
254+
from(compileKotlin)
255+
from(processResources)
256+
257+
into("lib") { from(configurations.runtimeClasspath) }
258+
259+
dirMode = 0b111101101 // 0755
260+
fileMode = 0b111101101 // 0755
261+
}
262+
263+
val packageLibs by creating(Zip::class) {
264+
into("java/lib") { from(configurations.runtimeClasspath) }
265+
266+
dirMode = 0b111101101 // 0755
267+
fileMode = 0b111101101 // 0755
268+
}
269+
270+
val packageSkinny by creating(Zip::class) {
271+
from(compileKotlin)
272+
from(processResources)
273+
}
274+
275+
build { dependsOn(packageSkinny) }
252276
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright (C) 2021. Alexander Rogalskiy. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package utils
17+
18+
import java.util.*
19+
20+
object CommonUtils {
21+
init {
22+
// To hide annoying warning on Windows
23+
System.setProperty("idea.use.native.fs.for.win", "false")
24+
}
25+
26+
/** A state machine for classifying qualified names. */
27+
private enum class TyParseState(val isSingleUnit: Boolean) {
28+
/** The start state. */
29+
START(false) {
30+
override fun next(n: JavaCaseFormat): TyParseState {
31+
return when (n) {
32+
JavaCaseFormat.UPPERCASE ->
33+
// if we see an UpperCamel later, assume this was a class
34+
// e.g. com.google.FOO.Bar
35+
AMBIGUOUS
36+
JavaCaseFormat.LOWER_CAMEL -> REJECT
37+
JavaCaseFormat.LOWERCASE ->
38+
// could be a package
39+
START
40+
JavaCaseFormat.UPPER_CAMEL -> TYPE
41+
}
42+
}
43+
},
44+
45+
/** The current prefix is a type. */
46+
TYPE(true) {
47+
override fun next(n: JavaCaseFormat): TyParseState {
48+
return when (n) {
49+
JavaCaseFormat.UPPERCASE, JavaCaseFormat.LOWER_CAMEL, JavaCaseFormat.LOWERCASE ->
50+
FIRST_STATIC_MEMBER
51+
JavaCaseFormat.UPPER_CAMEL -> TYPE
52+
}
53+
}
54+
},
55+
56+
/** The current prefix is a type, followed by a single static member access. */
57+
FIRST_STATIC_MEMBER(true) {
58+
override fun next(n: JavaCaseFormat): TyParseState {
59+
return REJECT
60+
}
61+
},
62+
63+
/** Anything not represented by one of the other states. */
64+
REJECT(false) {
65+
override fun next(n: JavaCaseFormat): TyParseState {
66+
return REJECT
67+
}
68+
},
69+
70+
/** An ambiguous type prefix. */
71+
AMBIGUOUS(false) {
72+
override fun next(n: JavaCaseFormat): TyParseState {
73+
return when (n) {
74+
JavaCaseFormat.UPPERCASE -> AMBIGUOUS
75+
JavaCaseFormat.LOWER_CAMEL, JavaCaseFormat.LOWERCASE -> REJECT
76+
JavaCaseFormat.UPPER_CAMEL -> TYPE
77+
}
78+
}
79+
};
80+
81+
/** Transition function. */
82+
abstract fun next(n: JavaCaseFormat): TyParseState
83+
}
84+
85+
/**
86+
* Returns the end index (inclusive) of the longest prefix that matches the naming conventions of
87+
* a type or static field access, or -1 if no such prefix was found.
88+
*
89+
* Examples:
90+
*
91+
* * ClassName
92+
* * ClassName.staticMemberName
93+
* * com.google.ClassName.InnerClass.staticMemberName
94+
*/
95+
internal fun typePrefixLength(nameParts: List<String>): Optional<Int> {
96+
var state = TyParseState.START
97+
var typeLength = Optional.empty<Int>()
98+
99+
for (i in nameParts.indices) {
100+
state = state.next(JavaCaseFormat.from(nameParts[i]))
101+
if (state === TyParseState.REJECT) {
102+
break
103+
}
104+
if (state.isSingleUnit) {
105+
typeLength = Optional.of(i)
106+
}
107+
}
108+
109+
return typeLength
110+
}
111+
112+
/** Case formats used in Java identifiers. */
113+
enum class JavaCaseFormat {
114+
UPPERCASE,
115+
LOWERCASE,
116+
UPPER_CAMEL,
117+
LOWER_CAMEL;
118+
119+
companion object {
120+
/** Classifies an identifier's case format. */
121+
internal fun from(name: String): JavaCaseFormat {
122+
var firstUppercase = false
123+
var hasUppercase = false
124+
var hasLowercase = false
125+
var first = true
126+
127+
for (element in name) {
128+
if (!Character.isAlphabetic(element.toInt())) {
129+
continue
130+
}
131+
if (first) {
132+
firstUppercase = Character.isUpperCase(element)
133+
first = false
134+
}
135+
hasUppercase = hasUppercase or Character.isUpperCase(element)
136+
hasLowercase = hasLowercase or Character.isLowerCase(element)
137+
}
138+
return if (firstUppercase) {
139+
if (hasLowercase) UPPER_CAMEL else UPPERCASE
140+
} else {
141+
if (hasUppercase) LOWER_CAMEL else LOWERCASE
142+
}
143+
}
144+
}
145+
}
146+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (C) 2021. Alexander Rogalskiy. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package utils
17+
18+
object RegexUtils {
19+
val NUMBERED_LIST_PATTERN = "[0-9]+\\.".toRegex()
20+
val COMPONENT_OPERATOR_REGEX = Regex("component\\d+")
21+
val KDOC_TAG_SKIP_FIRST_REFERENCE_REGEX = Regex("^@(param|property) (.+)")
22+
}

buildSrc/src/main/kotlin/utils/StringUtils.kt

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,49 @@ package utils
1818
import org.gradle.api.Project
1919
import java.io.File
2020

21-
private val whitespaceRegex = Regex("\\s")
21+
import java.util.regex.Pattern
22+
import java.util.regex.Pattern.MULTILINE
23+
24+
private const val whitespaceRegex = "\\s"
25+
private const val SPACE_TOMBSTONE = '\u0003'
26+
27+
private const val SLASH_STAR_ESCAPE = "\u0004\u0005"
28+
private const val STAR_SLASH_ESCAPE = "\u0005\u0004"
29+
30+
internal fun indexOfCommentEscapeSequences(s: String) =
31+
s.indexOfAny(listOf(SLASH_STAR_ESCAPE, STAR_SLASH_ESCAPE))
32+
33+
/**
34+
* kotlin-compiler's KDoc lexer doesn't correctly handle nested slash-star comments, so we escape
35+
* them into tombstones, format, then unescape.
36+
*/
37+
internal fun escapeKDoc(s: String): String {
38+
val startMarkerIndex = s.indexOf("/*")
39+
val endMarkerIndex = s.lastIndexOf("*/")
40+
41+
if (startMarkerIndex == -1 || endMarkerIndex == -1) {
42+
throw RuntimeException("KDoc with no /** and/or */")
43+
}
44+
45+
return s.substring(0, startMarkerIndex + 3) +
46+
s.substring(startMarkerIndex + 3, endMarkerIndex)
47+
.replace("/*", SLASH_STAR_ESCAPE)
48+
.replace("*/", STAR_SLASH_ESCAPE) +
49+
s.substring(endMarkerIndex)
50+
}
51+
52+
internal fun unescapeKDoc(s: String): String =
53+
s.replace(SLASH_STAR_ESCAPE, "/*").replace(STAR_SLASH_ESCAPE, "*/")
2254

2355
internal val String.dotIdentifier
2456
get() = replace("-", "")
2557
.replace(".", "")
26-
.replace(whitespaceRegex, "")
58+
.replace(Regex(whitespaceRegex), "")
2759

2860
internal val Project.dotIdentifier get() = "$group$name".dotIdentifier
2961

62+
internal fun String.indexOfWhitespaceTombstone() = this.indexOf(SPACE_TOMBSTONE)
63+
3064
internal fun String.nonEmptyPrepend(prepend: String) =
3165
if (isNotEmpty()) prepend + this else this
3266

@@ -39,6 +73,16 @@ internal fun String.toHyphenCase(): String {
3973
.joinToString(separator = "") { if (it[0].isUpperCase()) "-${it[0].toLowerCase()}" else it }
4074
}
4175

76+
/**
77+
* Google-java-format removes trailing spaces when it emits formatted code, which is a problem for
78+
* multiline string literals. We trick it by replacing the last trailing space in such cases with a
79+
* tombstone, a character that's unlikely to be used in a regular program. After formatting, we
80+
* replace it back to a space.
81+
*/
82+
internal fun replaceTrailingWhitespaceWithTombstone(s: String): String {
83+
return Pattern.compile(" ($)", MULTILINE).matcher(s).replaceAll("$SPACE_TOMBSTONE$1")
84+
}
85+
4286
/**
4387
* Executes the given command in specified working dir
4488
*

0 commit comments

Comments
 (0)