Skip to content

Commit

Permalink
🎨 Format code by jetbrains official code style (#150)
Browse files Browse the repository at this point in the history
* 🎨 Format code by jetbrains official code style

* 🎨 Make ktlint happy
  • Loading branch information
devkanro authored Feb 26, 2021
1 parent 51161ca commit 3af09dc
Show file tree
Hide file tree
Showing 119 changed files with 1,117 additions and 498 deletions.
199 changes: 129 additions & 70 deletions CHANGELOG.md

Large diffs are not rendered by default.

59 changes: 39 additions & 20 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
# Sisyphus
# Sisyphus

![JDK version](https://img.shields.io/badge/jdk-11-green?logo=java) ![Gradle Version](https://img.shields.io/badge/gradle-%5E6.5-green?logo=gradle) [![Maven Central](https://img.shields.io/maven-central/v/com.bybutter.sisyphus/sisyphus-bom)](https://mvnrepository.com/artifact/com.bybutter.sisyphus/sisyphus-bom) [![Dependencies](https://img.shields.io/librariesio/release/maven/com.bybutter.sisyphus:sisyphus-dependencies)](https://libraries.io/maven/com.bybutter.sisyphus:sisyphus-dependencies)

Sisyphus is the way how we provide backend services. It integrates all tools and libraries needed for designing API which follows the [Google API Improvement Proposals](https://aip.bybutter.com).
Sisyphus is the way how we provide backend services. It integrates all tools and libraries needed for designing API
which follows the [Google API Improvement Proposals](https://aip.bybutter.com).

## We are rolling a huge boulder

Due to analyzing product documents completely, it is not particularly difficult to write an exquisite and easy-to-use API at the beginning for most APIs.
Due to analyzing product documents completely, it is not particularly difficult to write an exquisite and easy-to-use
API at the beginning for most APIs.

However, many people will break the initial design of the API in the endless updates of products.

It's hard to create a strong and extensible API in the whole project lifetime, just like rolling a huge boulder endlessly up a steep hill.
It's hard to create a strong and extensible API in the whole project lifetime, just like rolling a huge boulder
endlessly up a steep hill.

So we need an all-encompassing guide book to guide us in creating, updating, and modifying APIs.
So we need an all-encompassing guide book to guide us in creating, updating, and modifying APIs.

The [Google API Improvement Proposals](https://aip.bybutter.com) is the all-encompassing guide book. Google created it in their rich and extensive API design experience. It laid the foundation for anyone to create an extensible API.
The [Google API Improvement Proposals](https://aip.bybutter.com) is the all-encompassing guide book. Google created it
in their rich and extensive API design experience. It laid the foundation for anyone to create an extensible API.

## Good tools can help you

Choosing good tools can help you 'rolling a huge boulder' faster and easier. Sisyphus provides and integrates many tools in your 'boulder rolling' route.
Choosing good tools can help you 'rolling a huge boulder' faster and easier. Sisyphus provides and integrates many tools
in your 'boulder rolling' route.

[**Kotlin**](https://kotlinlang.org/) is our target language. The mature JVM community and concise grammar are the reasons.
[**Kotlin**](https://kotlinlang.org/) is our target language. The mature JVM community and concise grammar are the
reasons.

[**Spring boot**](https://spring.io/projects/spring-boot) is our old friend to manage and organize our components.

[**gRPC**](https://grpc.io/) is our target API framework. Sisyphus also provides the [HTTP and gRPC Transcoding](https://aip.bybutter.com/127) component for the environment which isn't compatible with gRPC.
[**gRPC**](https://grpc.io/) is our target API framework. Sisyphus also provides
the [HTTP and gRPC Transcoding](https://aip.bybutter.com/127) component for the environment which isn't compatible with
gRPC.

[**Sisyphus Protobuf**](/lib/sisyphus-protobuf) is our customized protobuf runtime, which designed for Kotlin.

Expand All @@ -34,30 +42,38 @@ Choosing good tools can help you 'rolling a huge boulder' faster and easier. Sis

[**Sisyphus Middleware**](/middleware) is the way how we connect Sisyphus and other systems.

[**Sisyphus Configuration Artifact**](/middleware/sisyphus-configuration-artifact) is the way how we manage configurations and developing environment.
[**Sisyphus Configuration Artifact**](/middleware/sisyphus-configuration-artifact) is the way how we manage
configurations and developing environment.

[**Sisyphus Kubernetes gRPC client**](/middleware/sisyphus-grpc-client-kubernetes) is the way how we implement service discovery in Kubernetes.
[**Sisyphus Kubernetes gRPC client**](/middleware/sisyphus-grpc-client-kubernetes) is the way how we implement service
discovery in Kubernetes.

[**Sisyphus Protobuf Compiler**](/tools/sisyphus-protoc) is the way how we generate Kotlin codes by `.proto` files.

[**Sisyphus Project Plugin**](/tools/sisyphus-project-gradle-plugin) is the way how we manage project and configuring Gradle.
[**Sisyphus Project Plugin**](/tools/sisyphus-project-gradle-plugin) is the way how we manage project and configuring
Gradle.

[**Sisyphus Protobuf Plugin**](/tools/sisyphus-protobuf-gradle-plugin) is the way how we generate code by `.proto` files in Gradle.
[**Sisyphus Protobuf Plugin**](/tools/sisyphus-protobuf-gradle-plugin) is the way how we generate code by `.proto` files
in Gradle.

**And More** tools like [CEL(Common Expression Language)](https://github.com/google/cel-spec), [Filtering](https://aip.bybutter.com/160) and [Ordering](https://aip.bybutter.com/132#ordering) scripts will help you to design APIs following Google AIP.
**And More** tools like [CEL(Common Expression Language)](https://github.com/google/cel-spec)
, [Filtering](https://aip.bybutter.com/160) and [Ordering](https://aip.bybutter.com/132#ordering) scripts will help you
to design APIs following Google AIP.

## Rolling with Sisyphus

Ready to rolling boulder with Sisyphus already? Hold on! We need to plan our route first.

1. **System requirement**

- Gradle 6.7+
- JDK 11+
- Gradle 6.7+
- JDK 11+

2. **Configure Sisyphus with gradle.properties**

We use [gradle.properties](https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties) to configure global settings of Sisyphus and all Sisyphus projects.
We
use [gradle.properties](https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties)
to configure global settings of Sisyphus and all Sisyphus projects.

```properties
# [DEV,RT] Set developer name for developing environment.
Expand Down Expand Up @@ -93,7 +109,8 @@ Ready to rolling boulder with Sisyphus already? Hold on! We need to plan our rou
>
> **[RT]** for runtime environment properties.
`gradle.properties` are shared between Gradle and Spring. Sisyphus Project Plugin will load them and configure Gradle automatically. Sisyphus Configuration Artifact will load them for Spring Framework.
`gradle.properties` are shared between Gradle and Spring. Sisyphus Project Plugin will load them and configure Gradle
automatically. Sisyphus Configuration Artifact will load them for Spring Framework.

3. **Write Protobuf schemas**

Expand Down Expand Up @@ -157,7 +174,8 @@ Ready to rolling boulder with Sisyphus already? Hold on! We need to plan our rou

4. **Implement API**

API schema is ready now. The next step is to implement this API schema. Create a service project and refer to the schema project.
API schema is ready now. The next step is to implement this API schema. Create a service project and refer to the
schema project.

This is a sample service project `build.gradle.kts` config.

Expand Down Expand Up @@ -203,7 +221,8 @@ Ready to rolling boulder with Sisyphus already? Hold on! We need to plan our rou

5. **Run the Application**

The service project is just a non-runnable library. We need to create an application project to run our service projects.
The service project is just a non-runnable library. We need to create an application project to run our service
projects.

This is a sample application project `build.gradle.kts` config.

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

dependencies {
implementation(platform("com.bybutter.sisyphus:sisyphus-dependencies:protoc-SNAPSHOT"))
implementation(platform("com.bybutter.sisyphus:sisyphus-dependencies:higan-SNAPSHOT"))
implementation("com.bybutter.sisyphus.tools:sisyphus-protobuf-gradle-plugin")
implementation("com.bybutter.sisyphus.tools:sisyphus-project-gradle-plugin")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ open class BaseEncoding(val table: CharArray) {
val stream = BitOutputStream(output)

for (char in input) {
stream.writeInt(reverseMap[char]
?: throw IllegalArgumentException("Wrong base$bits input '$char'."), bits)
stream.writeInt(
reverseMap[char]
?: throw IllegalArgumentException("Wrong base$bits input '$char'."), bits
)
}
return output.toByteArray()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BitInputStream(private val source: InputStream) : InputStream() {
}

var read = 0
loop@for (i in 0 until bits) {
loop@ for (i in 0 until bits) {
when (read()) {
0 -> data.set(i, false)
1 -> data.set(i, true)
Expand All @@ -47,7 +47,7 @@ class BitInputStream(private val source: InputStream) : InputStream() {
var int = 0

var read = 0
loop@for (i in 0 until bits) {
loop@ for (i in 0 until bits) {
when (read()) {
1 -> int = int or (1 shl (bits - i - 1))
0 -> int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ fun String.toWindowsPath(): String {
fun String.toPlatformPath(): String {
return buildString {
for (ch in this@toPlatformPath) {
append(when (ch) {
'\\', '/' -> File.separatorChar
else -> ch
})
append(
when (ch) {
'\\', '/' -> File.separatorChar
else -> ch
}
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlin.math.sin
import kotlin.math.sqrt

typealias Vec2 = Pair<Double, Double>

val Vec2.x get() = first
val Vec2.y get() = second

Expand Down Expand Up @@ -63,6 +64,7 @@ fun Vec2.toCartesian(): Vec2 {
}

typealias Vec3 = Triple<Double, Double, Double>

val Vec3.x get() = first
val Vec3.y get() = second
val Vec3.z get() = third
Expand Down Expand Up @@ -110,6 +112,7 @@ fun Vec3.dot(other: Vec3): Double {
}

typealias Vec4 = Quat<Double, Double, Double, Double>

val Vec4.x get() = first
val Vec4.y get() = second
val Vec4.z get() = third
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.lang.reflect.Type
import java.util.concurrent.ConcurrentHashMap

class GenericType private constructor(raw: Class<*>, private val parameters: List<JvmType>) : SimpleType(raw),
ParameterizedType {
ParameterizedType {
companion object {
private val cache = ConcurrentHashMap<String, GenericType>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ abstract class JvmType protected constructor() : Type {
fun fromName(name: String): JvmType {
return when {
name == "?" -> OutWildcardType.STAR
name.startsWith("? extends ") -> OutWildcardType(name.substringAfter("? extends ").split(" & ").map { it.toType() as SimpleType })
name.startsWith("? super ") -> InWildcardType(name.substringAfter("? extends ").split(" & ").map { it.toType() as SimpleType })
name.startsWith("? extends ") -> OutWildcardType(
name.substringAfter("? extends ").split(" & ").map { it.toType() as SimpleType })
name.startsWith("? super ") -> InWildcardType(
name.substringAfter("? extends ").split(" & ").map { it.toType() as SimpleType })
name.indexOf('<') > 0 -> {
val raw = Class.forName(name.substringBefore('<'))
val parameters = name.substring(name.indexOf('<') + 1, name.lastIndexOf('>'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,21 @@ object BeanUtils {
}
}

inline fun <reified T> getBeansWithAnnotation(beanFactory: ListableBeanFactory, annotation: Class<out Annotation>): Map<String, T> {
inline fun <reified T> getBeansWithAnnotation(
beanFactory: ListableBeanFactory,
annotation: Class<out Annotation>
): Map<String, T> {
return getBeansWithAnnotation(beanFactory, T::class.java, annotation)
}

/**
* Get beans of specified type and annotation, if [beanFactory] is [ConfigurableBeanFactory] or [ApplicationContext] this function will return sorted beans.
*/
fun <T> getBeansWithAnnotation(beanFactory: ListableBeanFactory, type: Class<T>, annotation: Class<out Annotation>): Map<String, T> {
fun <T> getBeansWithAnnotation(
beanFactory: ListableBeanFactory,
type: Class<T>,
annotation: Class<out Annotation>
): Map<String, T> {
val factory = when (beanFactory) {
is ApplicationContext -> beanFactory.autowireCapableBeanFactory
else -> beanFactory
Expand All @@ -66,7 +73,11 @@ object BeanUtils {
}
}

fun <T> getSortedBeansWithAnnotation(beanFactory: ConfigurableListableBeanFactory, type: Class<T>, annotation: Class<out Annotation>): Map<String, T> {
fun <T> getSortedBeansWithAnnotation(
beanFactory: ConfigurableListableBeanFactory,
type: Class<T>,
annotation: Class<out Annotation>
): Map<String, T> {
return getSortedBeansWithCondition(beanFactory, type) { _, _, definition ->
val beanType = Class.forName(definition.beanClassName)
AnnotationUtils.getAnnotation(beanType, annotation) != null
Expand All @@ -76,7 +87,11 @@ object BeanUtils {
/**
* Get beans of specified type and annotation, if [beanFactory] is [ConfigurableBeanFactory] or [ApplicationContext] this function will return sorted beans.
*/
fun <T> getBeansWithCondition(beanFactory: ListableBeanFactory, type: Class<T>, condition: (String, ListableBeanFactory) -> Boolean): Map<String, T> {
fun <T> getBeansWithCondition(
beanFactory: ListableBeanFactory,
type: Class<T>,
condition: (String, ListableBeanFactory) -> Boolean
): Map<String, T> {
val factory = when (beanFactory) {
is ApplicationContext -> beanFactory.autowireCapableBeanFactory
else -> beanFactory
Expand All @@ -100,7 +115,11 @@ object BeanUtils {
return result
}

fun <T> getSortedBeansWithCondition(beanFactory: ConfigurableListableBeanFactory, type: Class<T>, condition: (String, ConfigurableBeanFactory, BeanDefinition) -> Boolean): Map<String, T> {
fun <T> getSortedBeansWithCondition(
beanFactory: ConfigurableListableBeanFactory,
type: Class<T>,
condition: (String, ConfigurableBeanFactory, BeanDefinition) -> Boolean
): Map<String, T> {
val names = beanFactory.getBeanNamesForType(type)
val beans = mutableMapOf<String, BeanDefinition>()

Expand All @@ -120,7 +139,8 @@ object BeanUtils {

private class BeanDefinitionOrderComparer(private val map: Map<String, BeanDefinition>) : Comparator<String> {
companion object {
private val ORDER_ATTRIBUTE = Conventions.getQualifiedAttributeName(ConfigurationClassPostProcessor::class.java, "order")
private val ORDER_ATTRIBUTE =
Conventions.getQualifiedAttributeName(ConfigurationClassPostProcessor::class.java, "order")
}

override fun compare(o1: String, o2: String): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import com.bybutter.sisyphus.string.case.WordSplitter

fun String.toCase(format: CaseFormat) = format.format(this)

fun String.toCase(formatter: CaseFormatter, splitter: WordSplitter = CommonWordSplitter) = formatter.format(splitter.split(this))
fun String.toCase(formatter: CaseFormatter, splitter: WordSplitter = CommonWordSplitter) =
formatter.format(splitter.split(this))

/** Converts a string to 'SCREAMING_SNAKE_CASE'. */
fun String.toScreamingSnakeCase() = toCase(ScreamingSnakeCaseFormatter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ object PathMatcher {
return si == str.length
}

private fun wildcardMatch(pat: CharSequence, p: Int, str: CharSequence, s: Int, pathDelimiters: Set<Char>): Boolean {
private fun wildcardMatch(
pat: CharSequence,
p: Int,
str: CharSequence,
s: Int,
pathDelimiters: Set<Char>
): Boolean {
var si = s
val pc = pat.getOrZero(p)
while (true) {
Expand Down Expand Up @@ -96,7 +102,13 @@ object PathMatcher {
}
}

private fun multiWildcardMatch(pat: CharSequence, p: Int, str: CharSequence, s: Int, pathDelimiters: Set<Char>): Boolean {
private fun multiWildcardMatch(
pat: CharSequence,
p: Int,
str: CharSequence,
s: Int,
pathDelimiters: Set<Char>
): Boolean {
// End of pattern, just check the end of string is '/' quickly.
var si = s
if (p >= pat.length && si < str.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ data class Version(val major: Int, val minor: Int, val patch: Int) : Comparable<
*/
fun isAtLeast(major: Int, minor: Int): Boolean =
this.major > major || (this.major == major &&
this.minor >= minor)
this.minor >= minor)

/**
* Returns `true` if this version is not less than the version specified
* with the provided [major], [minor] and [patch] components.
*/
fun isAtLeast(major: Int, minor: Int, patch: Int): Boolean =
this.major > major || (this.major == major &&
(this.minor > minor || this.minor == minor &&
this.patch >= patch))
(this.minor > minor || this.minor == minor &&
this.patch >= patch))

companion object {
fun parse(version: String): Version {
Expand Down
Loading

0 comments on commit 3af09dc

Please sign in to comment.