Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: commit files corrected by Detekt #1165

Merged
merged 14 commits into from
Oct 1, 2020
4 changes: 4 additions & 0 deletions .github/workflows/macos_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
with:
arguments: "clean build"

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[Auto-commit] Added filese fixed by Detekt"

- name: Codecov
uses: codecov/[email protected]
with:
Expand Down
12 changes: 12 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ configurations.all {

plugins {
kotlin(Plugins.Kotlin.PLUGIN_JVM) version Versions.KOTLIN
id(Plugins.DETEKT_PLUGIN) version Versions.DETEKT
id(Plugins.BEN_MANES_PLUGIN) version Versions.BEN_MANES
}

tasks.named("detekt") {
Sloox marked this conversation as resolved.
Show resolved Hide resolved
dependsOn(":test_runner:detekt")
dependsOn(":integration_tests:detekt")
dependsOn(":flank-scripts:detekt")
}

tasks.named("clean"){
Sloox marked this conversation as resolved.
Show resolved Hide resolved
dependsOn(":test_runner:clean")
dependsOn(":integration_tests:clean")
}

Sloox marked this conversation as resolved.
Show resolved Hide resolved
repositories {
jcenter()
mavenCentral()
Expand Down
35 changes: 25 additions & 10 deletions config/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 @@ -106,17 +106,19 @@ formatting:
active: true
android: false
autoCorrect: true
ArgumentListWrapping:
active: false
AnnotationOnSeparateLine:
active: false
autoCorrect: true
ChainWrapping:
active: true
active: false
Sloox marked this conversation as resolved.
Show resolved Hide resolved
autoCorrect: true
CommentSpacing:
active: true
autoCorrect: true
EnumEntryNameCase:
active: true
EnumEntryNameCase:
active: false
Sloox marked this conversation as resolved.
Show resolved Hide resolved
autoCorrect: false
Filename:
active: false
Expand All @@ -130,11 +132,14 @@ formatting:
autoCorrect: false
Indentation:
active: false
autoCorrect: false
autoCorrect: true
indentSize: 4
continuationIndentSize: 4
MaximumLineLength:
excludes: ['**/test/**', '**/*.Test.kt', '**/*.Spec.kt']
active: false
autoCorrect: true
maxLineLength: 120
ModifierOrdering:
active: true
autoCorrect: true
Expand All @@ -144,11 +149,15 @@ formatting:
active: true
autoCorrect: true
NoConsecutiveBlankLines:
excludes: ['**/test/**', '**/*.Test.kt', '**/*.Spec.kt']
active: true
autoCorrect: true
NoEmptyClassBody:
active: true
autoCorrect: true
NoEmptyFirstLineInMethodBlock:
excludes: ['**/test/**', '**/*.Test.kt', '**/*.Spec.kt']
active: true
NoItParamInMultilineLambda:
active: false
NoLineBreakAfterElse:
Expand Down Expand Up @@ -179,7 +188,8 @@ formatting:
active: true
autoCorrect: true
ParameterListWrapping:
active: true
excludes: ['**/test/**', '**/*.Test.kt', '**/*.Spec.kt']
active: false
autoCorrect: true
indentSize: 4
SpacingAroundColon:
Expand Down Expand Up @@ -257,7 +267,7 @@ naming:
propertyPattern: '[A-Za-z][_A-Za-z0-9]*'
privatePropertyPattern: '(_)?[A-Za-z][A-Za-z0-9]*'
VariableMaxLength:
active: false
active: true
maximumVariableNameLength: 64
VariableMinLength:
active: false
Expand Down Expand Up @@ -313,6 +323,8 @@ potential-bugs:

style:
active: true
ClassOrdering:
active: false
CollapsibleIfStatements:
active: true
DataClassContainsFunctions:
Expand Down Expand Up @@ -346,6 +358,7 @@ style:
ForbiddenPublicDataClass:
active: true
MaxLineLength:
excludes: ['**/test/**', '**/*.Test.kt', '**/*.Spec.kt']
active: false
maxLineLength: 120
excludePackageStatements: true
Expand Down Expand Up @@ -405,6 +418,8 @@ style:
active: true
UnusedPrivateClass:
active: true
UnderscoresInNumericLiterals:
active: false
UnusedPrivateMember:
active: true
allowedNames: '(_|ignored|expected|serialVersionUID|plus)'
Expand Down
4 changes: 3 additions & 1 deletion flank-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
kotlin(Plugins.Kotlin.PLUGIN_JVM)
kotlin(Plugins.Kotlin.PLUGIN_SERIALIZATION) version Versions.KOTLIN
id(Plugins.PLUGIN_SHADOW_JAR) version Versions.SHADOW
id(Plugins.DETEKT_PLUGIN) version Versions.DETEKT
id(Plugins.DETEKT_PLUGIN)
}

val artifactID = "flankScripts"
Expand Down Expand Up @@ -38,7 +38,9 @@ repositories {
detekt {
input = files("src/main/kotlin", "src/test/kotlin")
config = files("../config/detekt.yml")
parallel = true
autoCorrect = true

reports {
xml {
enabled = false
Expand Down
15 changes: 15 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2560m -Dfile.encoding=UTF-8
kotlin.code.style=official
org.gradle.parallel=true
org.gradle.daemon=true
3 changes: 2 additions & 1 deletion integration_tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
kotlin(Plugins.Kotlin.PLUGIN_JVM)
id(Plugins.DETEKT_PLUGIN) version Versions.DETEKT
id(Plugins.DETEKT_PLUGIN)
}

Sloox marked this conversation as resolved.
Show resolved Hide resolved
group = "org.flank"
Expand All @@ -19,6 +19,7 @@ detekt {
config = files("../config/detekt.yml")
autoCorrect = true //auto format for detekt via klint
buildUponDefaultConfig = true // preconfigure defaults
parallel = true

reports {
html.enabled = true // observe findings in your browser with structure and code snippets
Expand Down
20 changes: 10 additions & 10 deletions test_runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
application
jacoco
kotlin(Plugins.Kotlin.PLUGIN_JVM)
id(Plugins.DETEKT_PLUGIN) version Versions.DETEKT
id(Plugins.DETEKT_PLUGIN)
id(Plugins.JFROG_BINTRAY) version Versions.BINTRAY
id(Plugins.MAVEN_PUBLISH)
id(Plugins.PLUGIN_SHADOW_JAR) version Versions.SHADOW
Expand Down Expand Up @@ -132,12 +132,18 @@ publishing {
}
}

subprojects {
Sloox marked this conversation as resolved.
Show resolved Hide resolved
tasks.withType<Test> {
maxParallelForks = Runtime.getRuntime().availableProcessors()
}
}

detekt {
failFast = true // fail build on any finding
input = files("src/main/kotlin", "src/test/kotlin")
config = files("../config/detekt.yml")
autoCorrect = true //auto format for detekt via klint
buildUponDefaultConfig = true // preconfigure defaults
parallel = true
failFast = true // fail build on any finding
autoCorrect = true

reports {
html.enabled = true // observe findings in your browser with structure and code snippets
Expand All @@ -146,12 +152,6 @@ detekt {
}
}

subprojects {
tasks.withType<Test> {
maxParallelForks = Runtime.getRuntime().availableProcessors() / 2
}
}

// Kotlin dsl
tasks.withType<io.gitlab.arturbosch.detekt.Detekt> {
// Target version of the generated JVM bytecode. It is used for type resolution.
Expand Down
1 change: 0 additions & 1 deletion test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ object AndroidCatalog {
versionMap.getOrPut(projectId) { deviceCatalog(projectId).versions.map { it.id } }

fun supportedDeviceConfig(modelId: String, versionId: String, projectId: String): DeviceConfigCheck {

val foundModel = deviceCatalog(projectId).models.find { it.id == modelId } ?: return UnsupportedModelId
if (!androidVersionIds(projectId).contains(versionId)) return UnsupportedVersionId

Expand Down
72 changes: 42 additions & 30 deletions test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ object ArgsHelper {
throw FlankGeneralError("'$file' $name doesn't exist")
}

private fun String.convertToWindowsPath() = this.replace("/", "\\").replaceFirst("~", System.getProperty("user.home"))
private fun String.convertToWindowsPath() =
this.replace("/", "\\").replaceFirst("~", System.getProperty("user.home"))

private fun String.exist() =
if (startsWith(GCS_PREFIX)) GcStorage.exist(this) else File(this).exists()
if (startsWith(GCS_PREFIX)) GcStorage.exist(this) else File(this).exists()

fun assertCommonProps(args: IArgs) {
assertNotEmpty(
args.project, "The project is not set. Define GOOGLE_CLOUD_PROJECT, set project in flank.yml\n" +
args.project,
"The project is not set. Define GOOGLE_CLOUD_PROJECT, set project in flank.yml\n" +
"or save service account credential to ${defaultCredentialPath}\n" +
" See https://github.com/GoogleCloudPlatform/google-cloud-java#specifying-a-project-id"
)
Expand Down Expand Up @@ -115,7 +117,12 @@ object ArgsHelper {
GcStorage.storage.get(bucket, path) ?: throw FlankGeneralError("The file at '$uri' does not exist")
}

fun validateTestMethods(testTargets: List<String>, validTestMethods: Collection<String>, from: String, skipValidation: Boolean = useMock) {
fun validateTestMethods(
testTargets: List<String>,
validTestMethods: Collection<String>,
from: String,
skipValidation: Boolean = useMock
) {
val missingMethods = testTargets - validTestMethods

if (!skipValidation && missingMethods.isNotEmpty()) throw FlankConfigurationError("$from is missing methods: $missingMethods.\nValid methods:\n$validTestMethods")
Expand All @@ -132,17 +139,17 @@ object ArgsHelper {
// Due to permission issues, the user may not be able to list or create buckets.
fun createGcsBucket(projectId: String, bucket: String): String {
if (bucket.isBlank()) return GcToolResults.getDefaultBucket(projectId)
?: throw FlankGeneralError("Failed to make bucket for $projectId")
?: throw FlankGeneralError("Failed to make bucket for $projectId")
if (useMock) return bucket

// test lab supports using a special free storage bucket
// because we don't have access to the root account, it won't show up in the storage list.
if (bucket.startsWith("test-lab-")) return bucket

val storage = StorageOptions.newBuilder()
.setCredentials(FtlConstants.credential)
.setProjectId(projectId)
.build().service
.setCredentials(FtlConstants.credential)
.setProjectId(projectId)
.build().service
val bucketLabel = mapOf("flank" to "")
val storageLocation = "us-central1"

Expand All @@ -159,11 +166,11 @@ object ArgsHelper {

try {
storage.create(
BucketInfo.newBuilder(bucket)
.setStorageClass(StorageClass.REGIONAL)
.setLocation(storageLocation)
.setLabels(bucketLabel)
.build()
BucketInfo.newBuilder(bucket)
.setStorageClass(StorageClass.REGIONAL)
.setLocation(storageLocation)
.setLabels(bucketLabel)
.build()
)
} catch (e: Exception) {
println("Warning: Failed to make bucket for $projectId\nCause: ${e.message}")
Expand All @@ -177,9 +184,9 @@ object ArgsHelper {
if (!defaultCredentialPath.toFile().exists()) return null

return JsonObjectParser(JSON_FACTORY).parseAndClose(
Files.newInputStream(defaultCredentialPath),
Charsets.UTF_8,
GenericJson::class.java
Files.newInputStream(defaultCredentialPath),
Charsets.UTF_8,
GenericJson::class.java
)["project_id"] as String
} catch (e: Exception) {
println("Parsing $defaultCredentialPath failed:")
Expand Down Expand Up @@ -231,22 +238,27 @@ object ArgsHelper {
}
val (ignoredTests, testsToExecute) = filteredTests.partition { it.ignored }
val shards = if (args.disableSharding) {
listOf(Chunk(testsToExecute.map {
TestMethod(
name = it.testName,
isParameterized = it.isParameterizedClass,
time = 0.0
listOf(
Chunk(
testsToExecute.map {
TestMethod(
name = it.testName,
isParameterized = it.isParameterizedClass,
time = 0.0
)
}
)
}))
)
} else {
val oldTestResult = GcStorage.downloadJunitXml(args) ?: JUnitTestResult(mutableListOf())
val shardCount = forcedShardCount ?: shardCountByTime(testsToExecute, oldTestResult, args)
createShardsByShardCount(testsToExecute, oldTestResult, args, shardCount).map { Chunk(it.testMethods) }
}

return CalculateShardsResult(
testMethodsAlwaysRun(shards, args),
ignoredTestCases = ignoredTests.map { it.testName })
testMethodsAlwaysRun(shards, args),
ignoredTestCases = ignoredTests.map { it.testName }
)
}

private fun testMethodsAlwaysRun(shards: List<Chunk>, args: IArgs): List<Chunk> {
Expand All @@ -258,9 +270,9 @@ object ArgsHelper {
}

fun String.normalizeFilePath(): String =
if (startsWith(GCS_PREFIX)) this
else try {
ArgsHelper.evaluateFilePath(this)
} catch (e: Throwable) {
this
}
if (startsWith(GCS_PREFIX)) this
else try {
ArgsHelper.evaluateFilePath(this)
} catch (e: Throwable) {
this
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ abstract class CommonRunCommand {
@CommandLine.Option(
names = ["--obfuscate"],
description = ["Replacing internal test names with unique identifiers when using --dump-shards option " +
"to avoid exposing internal details"])
"to avoid exposing internal details"]
)
var obfuscate: Boolean = false
}
Loading