Skip to content

Commit

Permalink
SarifFixAdapter (#4)
Browse files Browse the repository at this point in the history
### What's done:
* Introduce primary logic and tests
* Apply fix objects from SARIF to the target files (single line changes)
  • Loading branch information
kgevorkyan authored Dec 19, 2022
1 parent 5e2f0b4 commit 999c609
Show file tree
Hide file tree
Showing 27 changed files with 1,613 additions and 174 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:

jobs:
build_and_test:
# Temporary disable action
if: ${{ false }}
name: Build and test
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -97,7 +99,8 @@ jobs:

report:
name: Publish JUnit test results
if: ${{ always() }}
# Temporary disable action
if: ${{ false }}
needs: build_and_test
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:

jobs:
detekt_check:
# Temporary disable action
if: ${{ false }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/diktat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:

jobs:
diktat_check:
# Temporary disable action
if: ${{ false }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ fun Project.configureDiktat() {
"buildSrc/**/*.kts",
"*.kts"
)
exclude("build", "buildSrc/build")
exclude("build", "buildSrc/build", "src/**/resources/*")
} else {
include("src/**/*.kt", "*.kts", "src/**/*.kts")
exclude("build/**")
exclude("build/**", "src/**/resources/*")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,7 @@ fun Project.configureJacoco() {
}
}

// `application` plugin creates jacocoTestReport task in plugin section (this is definitely incorrect behavior)
// AFTER that in "com.saveourtool.sarifutils.buildutils.kotlin-library" we try to register this task once again and fail
// so the order of plugins in `apply` is critically important
val jacocoTestReportTask = if (project.name == "fixpatches") {
val jacocoTestReportTask by tasks.named("jacocoTestReport", configure)
jacocoTestReportTask
} else {
val jacocoTestReportTask by tasks.register("jacocoTestReport", configure)
jacocoTestReportTask
}
val jacocoTestReportTask by tasks.register("jacocoTestReport", configure)

jvmTestTask.finalizedBy(jacocoTestReportTask)
jacocoTestReportTask.dependsOn(jvmTestTask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ kotlin {
}
}
val nativeTargets = listOf(linuxX64(), mingwX64(), macosX64())
if (project.name == "save-common") {
// additionally, save-common should be available for JS too
// fixme: shouldn't rely on hardcoded project name here
js(BOTH).browser()

// store yarn.lock in the root directory
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension> {
lockFileDirectory = rootProject.projectDir
}
}

if (hasProperty("disableRedundantTargets") && (property("disableRedundantTargets") as String?) != "false") {
// with this flag we exclude targets that are present on multiple OS to speed up build
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@file:Suppress(
"HEADER_MISSING_OR_WRONG_COPYRIGHT",
"MISSING_KDOC_TOP_LEVEL",
"MISSING_KDOC_CLASS_ELEMENTS",
"PACKAGE_NAME_INCORRECT_PREFIX",
"PACKAGE_NAME_INCORRECT_PATH",
"FILE_INCORRECT_BLOCKS_ORDER",
"WRONG_INDENTATION",
"NO_BRACES_IN_CONDITIONALS_AND_LOOPS",
)

// Copied from https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/jvm/tasks/KotlinJvmTest.kt
// which needs to be recompiled with a newer Gradle API to address https://youtrack.jetbrains.com/issue/KT-54634

/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/

package org.jetbrains.kotlin.gradle.targets.jvm.tasks

import org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec
import org.gradle.api.internal.tasks.testing.TestDescriptorInternal
import org.gradle.api.internal.tasks.testing.TestExecuter
import org.gradle.api.internal.tasks.testing.TestResultProcessor
import org.gradle.api.internal.tasks.testing.TestStartEvent
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.testing.Test

@CacheableTask
open class KotlinJvmTest : Test() {
@Input
@Optional
var targetName: String? = null

override fun createTestExecuter(): TestExecuter<JvmTestExecutionSpec> =
if (targetName != null) Executor(
super.createTestExecuter(),
targetName!!
)
else super.createTestExecuter()

class Executor(
private val delegate: TestExecuter<JvmTestExecutionSpec>,
private val targetName: String
) : TestExecuter<JvmTestExecutionSpec> by delegate {
override fun execute(testExecutionSpec: JvmTestExecutionSpec, testResultProcessor: TestResultProcessor) {
delegate.execute(testExecutionSpec, object : TestResultProcessor by testResultProcessor {
override fun started(test: TestDescriptorInternal, event: TestStartEvent) {
val myTest = object : TestDescriptorInternal by test {
override fun getDisplayName(): String = "${test.displayName}[$targetName]"
override fun getClassName(): String? = test.className?.replace('$', '.')
override fun getClassDisplayName(): String? = test.classDisplayName?.replace('$', '.')
}
testResultProcessor.started(myTest, event)
}
})
}
}
}
63 changes: 1 addition & 62 deletions fixpatches/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,79 +1,18 @@
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem
import org.gradle.nativeplatform.platform.internal.DefaultOperatingSystem
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

plugins {
application
id("com.saveourtool.sarifutils.buildutils.kotlin-library")
}

application {
mainClass.set("com.saveourtool.sarifutils.cli.MainKt")
}

kotlin {
val os = getCurrentOperatingSystem()

jvm()

registerNativeBinaries(os, this)

sourceSets {
val commonMain by getting {
dependencies {
api(libs.okio)
implementation(libs.kotlinx.serialization.json)
implementation(libs.sarif4k)
implementation(libs.multiplatform.diff)
}
}
}

linkProperExecutable(os)
}

/**
* @param os
* @param kotlin
* @throws GradleException
*/
fun registerNativeBinaries(os: DefaultOperatingSystem, kotlin: KotlinMultiplatformExtension) {
val saveTarget = when {
os.isWindows -> kotlin.mingwX64()
os.isLinux -> kotlin.linuxX64()
os.isMacOsX -> kotlin.macosX64()
else -> throw GradleException("Unknown operating system $os")
}

configure(listOf(saveTarget)) {
binaries {
val name = "sarifutils-${project.version}-${this@configure.name}"
executable {
this.baseName = name
entryPoint = "com.saveourtool.sarifutils.cli.main"
}
}
}
}

/**
* @param os
* @throws GradleException
*/
fun linkProperExecutable(os: DefaultOperatingSystem) {
val linkReleaseExecutableTaskProvider = when {
os.isLinux -> tasks.getByName("linkReleaseExecutableLinuxX64")
os.isWindows -> tasks.getByName("linkReleaseExecutableMingwX64")
os.isMacOsX -> tasks.getByName("linkReleaseExecutableMacosX64")
else -> throw GradleException("Unknown operating system $os")
}
project.tasks.register("linkReleaseExecutableMultiplatform") {
dependsOn(linkReleaseExecutableTaskProvider)
}

// disable building of some binaries to speed up build
// possible values: `all` - build all binaries, `debug` - build only debug binaries
val enabledExecutables = if (hasProperty("enabledExecutables")) property("enabledExecutables") as String else null
if (enabledExecutables != null && enabledExecutables != "all") {
linkReleaseExecutableTaskProvider.enabled = false
}
}

This file was deleted.

Loading

0 comments on commit 999c609

Please sign in to comment.