Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
update detekt config
Browse files Browse the repository at this point in the history
add copyright header
clean code
  • Loading branch information
lookup-cat committed May 13, 2022
1 parent fab4bb7 commit bd3c62b
Show file tree
Hide file tree
Showing 41 changed files with 800 additions and 200 deletions.
21 changes: 4 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ buildscript {
allprojects {
group = "org.ktorm"
version = "1.0"
}

subprojects {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.allWarningsAsErrors = true
Expand All @@ -24,25 +26,10 @@ allprojects {
options.encoding = "UTF-8"
}

val detekt by configurations.creating
val detektVersion:String by project

tasks.register<JavaExec>("detekt") {
mainClass.set("io.gitlab.arturbosch.detekt.cli.Main")
classpath = detekt
val input = "${projectDir}/src/main/kotlin"
val config = "${rootDir}/detekt.yml"
val params = listOf("-i", input, "-c", config)
args(params)
}

dependencies {
detekt("io.gitlab.arturbosch.detekt:detekt-cli:${detektVersion}")
detekt("io.gitlab.arturbosch.detekt:detekt-formatting:${detektVersion}")
}

repositories {
mavenCentral()
jcenter()
}

configureDetekt()
}
38 changes: 38 additions & 0 deletions buildSrc/src/main/kotlin/DetektTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.gradle.api.Project
import org.gradle.api.tasks.JavaExec
import org.gradle.kotlin.dsl.*

fun Project.configureDetekt() {
val detekt by configurations.creating
val detektVersion: String by project

dependencies {
detekt("io.gitlab.arturbosch.detekt:detekt-cli:${detektVersion}")
detekt("io.gitlab.arturbosch.detekt:detekt-formatting:${detektVersion}")
}

tasks.register<JavaExec>("detekt") {
mainClass.set("io.gitlab.arturbosch.detekt.cli.Main")
classpath = detekt
val input = "${projectDir}/src/main/kotlin"
val config = "${rootDir}/detekt.yml"
val params = listOf("-i", input, "-c", config)
args(params)
}
}
20 changes: 18 additions & 2 deletions buildSrc/src/main/kotlin/MavenPublishing.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.jvm.tasks.Jar
Expand Down Expand Up @@ -73,13 +89,13 @@ fun Project.configureMavenPublishing() {
}
}
}
signing {
/*signing {
val keyId = System.getenv("GPG_KEY_ID")
val secretKey = System.getenv("GPG_SECRET_KEY")
val password = System.getenv("GPG_PASSWORD")
assert(!project.version.toString().endsWith("SNAPSHOT"))
useInMemoryPgpKeys(keyId, secretKey, password)
sign(publications["dist"])
}
}*/
}
17 changes: 16 additions & 1 deletion buildSrc/src/main/kotlin/PublishingExt.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.publish.PublicationContainer
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.tasks.SourceSetContainer
Expand Down
37 changes: 18 additions & 19 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
build:
maxIssues: 0
weights:
# complexity: 2
# LongParameterList: 1
# style: 1
# comments: 1
# complexity: 2
# LongParameterList: 1
# style: 1
# comments: 1

processors:
active: true
Expand Down Expand Up @@ -63,10 +63,10 @@ complexity:
active: true
threshold: 600
LongMethod:
active: true
active: false
threshold: 60
LongParameterList:
active: true
active: false
functionThreshold: 6
constructorThreshold: 6
ignoreDefaultParameters: true
Expand Down Expand Up @@ -156,22 +156,22 @@ exceptions:
TooGenericExceptionCaught:
active: false
exceptionNames:
- ArrayIndexOutOfBoundsException
- Error
- Exception
- IllegalMonitorStateException
- NullPointerException
- IndexOutOfBoundsException
- RuntimeException
- Throwable
- ArrayIndexOutOfBoundsException
- Error
- Exception
- IllegalMonitorStateException
- NullPointerException
- IndexOutOfBoundsException
- RuntimeException
- Throwable
allowedExceptionNameRegex: "^(_|(ignore|expected).*)"
TooGenericExceptionThrown:
active: true
exceptionNames:
- Error
- Exception
- Throwable
- RuntimeException
- Error
- Exception
- Throwable
- RuntimeException

formatting:
active: true
Expand All @@ -194,7 +194,6 @@ formatting:
active: true
autoCorrect: false
indentSize: 4
continuationIndentSize: 4
MaximumLineLength:
active: true
maxLineLength: 120
Expand Down
17 changes: 16 additions & 1 deletion ktorm-ksp-api/src/main/kotlin/org/ktorm/ksp/api/Column.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ktorm.ksp.api

import org.ktorm.entity.Entity
Expand Down Expand Up @@ -42,7 +58,6 @@ public annotation class Column(
*/
val propertyName: String = "",


/**
* Generate the [Table.references] method for the table property, bind the column to the reference table,
* and the reference table is the generated table of the property type.
Expand Down
37 changes: 32 additions & 5 deletions ktorm-ksp-api/src/main/kotlin/org/ktorm/ksp/api/Converter.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ktorm.ksp.api

import org.ktorm.schema.BaseTable
Expand Down Expand Up @@ -42,28 +58,39 @@ import kotlin.reflect.KClass
public sealed interface Converter

/**
* Specify [T] type to convert to Column type
* Specify [T] type to convert to Column type.
* @see [org.ktorm.ksp.api.Column.converter]
* @see [KtormKspConfig.singleTypeConverters]
*/
public interface SingleTypeConverter<T : Any> : Converter {

/**
* Convert [T] type to Column<T> type.
*/
public fun convert(table: BaseTable<*>, columnName: String, propertyType: KClass<T>): Column<T>
}


/**
* Specify any type to convert to Column type
* Specify any type to convert to Column type.
* @see [org.ktorm.ksp.api.Column.converter]
*/
public interface MultiTypeConverter : Converter {

/**
* Convert [T] type to Column<T> type.
*/
public fun <T : Any> convert(table: BaseTable<*>, columnName: String, propertyType: KClass<T>): Column<T>
}

/**
* Specify enum type to convert to Column type
* Specify enum type to convert to Column type.
* @see [org.ktorm.ksp.api.Column.converter]
* @see [KtormKspConfig.enumConverter]
*/
public interface EnumConverter : Converter {

/**
* Convert [E] type to Column<E> type.
*/
public fun <E : Enum<E>> convert(table: BaseTable<*>, columnName: String, propertyType: KClass<E>): Column<E>
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ktorm.ksp.api

import org.ktorm.entity.EntitySequence

/**
* Check whether the entity sequence has been modified.
* @throws UnsupportedOperationException If the entity sequence has been modified
*/
public fun EntitySequence<*, *>.checkIfSequenceModified() {
val isModified = expression.where != null
|| expression.groupBy.isNotEmpty()
Expand Down
20 changes: 18 additions & 2 deletions ktorm-ksp-api/src/main/kotlin/org/ktorm/ksp/api/Ignore.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ktorm.ksp.api

/**
* Specifies to ignore this property and not generate column definitions
* Specifies to ignore this property and not generate column definitions.
*/
@Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.SOURCE)
public annotation class Ignore
public annotation class Ignore
22 changes: 19 additions & 3 deletions ktorm-ksp-api/src/main/kotlin/org/ktorm/ksp/api/KtormKspConfig.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ktorm.ksp.api

import org.ktorm.schema.BaseTable
Expand Down Expand Up @@ -43,19 +59,19 @@ public annotation class KtormKspConfig(
val namingStrategy: KClass<out NamingStrategy> = Nothing::class,

/**
* Default extension code generate configuration
* Default extension code generate configuration.
*/
val extension: ExtensionGenerator = ExtensionGenerator()
)

/**
* Default extension build configuration
* Default extension build configuration.
*/
@Retention(AnnotationRetention.SOURCE)
public annotation class ExtensionGenerator(

/**
* Generate EntitySequence Extension Property
* Generate EntitySequence Extension Property.
* ```kotlin
* val Database.employees: EntitySequence<Employee,Employees>
* get() = this.sequenceOf(Employees)
Expand Down
Loading

0 comments on commit bd3c62b

Please sign in to comment.