Compare commits

...

16 Commits

Author SHA1 Message Date
Alexey Ganin 1baa9ce618 Merge branch 'feature/gradle_8_support' into gradle8_to_java17 2025-03-04 17:04:38 +03:00
Alexey Ganin 2ddf356387 fix kotlin dsl 2025-03-04 16:47:34 +03:00
Sergey Vlasenko 09d3294a5b Merge pull request 'Revert "feature add outputs for apiGenerator, stringGenerator"' (#27) from fix_build_issues into feature/java_17_support
Reviewed-on: #27
Reviewed-by: Daniil Bakherov <daniil.bakherov@noreply.localhost>
2024-04-03 14:11:25 +03:00
Sergey Vlasenko a8b167af0f Revert "feature add outputs for apiGenerator, stringGenerator"
This reverts commit ab6a83aee0.
2024-04-03 14:05:57 +03:00
Sergey Vlasenko 2ebdc7e33f Merge pull request 'feature add outputs for apiGenerator, stringGenerator' (#25) from feature/MB-42563 into feature/java_17_support
Reviewed-on: #25
Reviewed-by: Daniil Bakherov <daniil.bakherov@noreply.localhost>
2024-03-25 17:46:19 +03:00
Sergey Vlasenko ab6a83aee0 feature add outputs for apiGenerator, stringGenerator 2024-03-25 12:55:37 +03:00
Sergey Vlasenko 6df29f2101 Merge pull request 'feature add detektAnalysis task' (#24) from detekt_analysis into feature/java_17_support
Reviewed-on: #24
2024-03-20 16:11:56 +03:00
Sergey Vlasenko dca38422f3 feature add detektAnalysis task 2024-03-19 16:52:12 +03:00
Sergey Vlasenko e3437f34c1 Merge pull request 'feature add support java 17, gradle 8' (#23) from gradle_8 into feature/gradle_8_support
Reviewed-on: #23
2024-03-06 23:52:48 +03:00
Sergey Vlasenko a6dcd67a81 feature add support java 17, gradle 8 2024-03-06 12:57:36 +03:00
Konstantin Kuzhim 5c46386ebf update BuildScripts to include copy task in AndroidLinter.kt 2023-02-07 14:26:50 +07:00
Kirill Nayduik 3cc63ffe5e Ignore WrongTimberUsageDetector error 2022-05-11 19:10:22 +03:00
Kirill Nayduik ec358728eb Set lintConfig file direction 2022-05-11 17:40:08 +03:00
Kirill Nayduik 78024ea1a6 Add script for setting lintOptions 2022-05-11 17:10:27 +03:00
Kirill Nayduik 5e7a39d14d Add comments for temporary workaround to avoid Android Linter configuration error 2022-04-29 22:13:42 +03:00
Kirill Nayduik e175e66e57 Update parcelize implementation 2022-04-28 16:56:21 +03:00
9 changed files with 122 additions and 34 deletions

View File

@ -1,33 +1,33 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`java-gradle-plugin`
`kotlin-dsl`
id("java-gradle-plugin")
id("org.gradle.kotlin.kotlin-dsl") version "4.1.2"
}
// The kotlin-dsl plugin requires a repository to be declared
repositories {
jcenter()
google()
gradlePluginPortal()
}
dependencies {
// android gradle plugin, required by custom plugin
implementation("com.android.tools.build:gradle:4.0.1")
implementation("com.android.tools.build:gradle:7.1.3")
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.10.0")
implementation("de.aaschmid:gradle-cpd-plugin:3.1")
implementation("de.aaschmid:gradle-cpd-plugin:3.3")
// kotlin plugin, required by custom plugin
implementation(kotlin("gradle-plugin", embeddedKotlinVersion))
implementation(kotlin("gradle-plugin", "1.8.10"))
gradleKotlinDsl()
implementation(kotlin("stdlib-jdk8"))
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
gradlePlugin {

View File

@ -52,9 +52,13 @@ abstract class ApiGeneratorPlugin : Plugin<Project> {
val outputLanguage = extension.outputLanguage ?: throw IllegalStateException("Configure output language code for api generator plugin")
javaexec {
main = "-jar"
mainClass.set("-jar")
workingDir = rootDir
args = listOfNotNull(
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
"--add-opens",
"java.base/java.time=ALL-UNNAMED",
configurations.getByName("apiGenerator").asPath,
"generate-client-code",
"--output-language",
@ -68,7 +72,7 @@ abstract class ApiGeneratorPlugin : Plugin<Project> {
"--package-name",
extension.outputPackageName,
"--recreate_output_dirs",
extension.recreateOutputDir.toString()
extension.recreateOutputDir.toString(),
)
}
}

View File

@ -1,9 +1,7 @@
package static_analysis.linters
import com.android.build.gradle.AppExtension
import com.android.build.gradle.AppPlugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.findByType
import static_analysis.errors.AndroidLintError
import static_analysis.errors.StaticAnalysisError
import static_analysis.plugins.StaticAnalysisExtension
@ -33,22 +31,10 @@ class AndroidLinter : Linter {
.flatten()
override fun setupForProject(project: Project, extension: StaticAnalysisExtension) {
project.beforeEvaluate {
subprojects
.mapNotNull { it.extensions.findByType<AppExtension>() }
.first()
.lintOptions.apply {
isAbortOnError = false
isCheckAllWarnings = true
isWarningsAsErrors = false
xmlReport = true
htmlReport = false
isCheckDependencies = true
disable("MissingConstraints", "VectorRaster")
xmlOutput = getLintReportFile()
lintConfig = file("${extension.buildScriptDir}/static_analysis_configs/lint.xml")
}
}
// Make sure to set lint options manually in modules gradle file
// Otherwise you will get java.io.FileNotFoundException
// See issue: https://github.com/TouchInstinct/BuildScripts/issues/310
}
override fun getTaskNames(project: Project, buildType: String?): List<String> {
@ -62,11 +48,14 @@ class AndroidLinter : Linter {
.mapNotNull { subproject: Project ->
subproject
.tasks
.find { task -> task.name.contains(buildType, ignoreCase = true) && task.name.contains("lint") }
?.path
.filter { task ->
task.name.equals("lint${buildType}", ignoreCase = true)
|| task.name.equals("copy${buildType}AndroidLintReports", ignoreCase = true)
}
.map { it.path }
}
.flatten()
}
private fun Project.getLintReportFile() = file("${rootProject.buildDir}/reports/lint-report.xml")
}

View File

@ -42,7 +42,7 @@ class CpdLinter : Linter {
}
tasks.withType<Cpd> {
reports.xml.required.set(true)
reports.xml.destination = getCpdReportFile()
reports.xml.outputLocation.set(getCpdReportFile())
ignoreFailures = true
source = getSources(extension.excludes)
}

View File

@ -2,15 +2,24 @@ package static_analysis.linters
import io.gitlab.arturbosch.detekt.Detekt
import org.gradle.api.Project
import org.gradle.api.file.FileTree
import static_analysis.errors.DetektError
import static_analysis.errors.StaticAnalysisError
import static_analysis.plugins.StaticAnalysisExtension
import static_analysis.utils.getSources
import static_analysis.utils.runCommand
import static_analysis.utils.typedChildren
import static_analysis.utils.xmlParser
import java.io.File
class DetektLinter : Linter {
private companion object {
const val TAG = "DetektLinter"
const val ONLY_DIFFS_FLAG = "only-diffs"
const val GET_GIT_DIFFS_COMMAND = "git diff --name-only --ignore-submodules"
}
override val name: String = "Detekt"
override fun getErrors(project: Project): List<StaticAnalysisError> = xmlParser(project.getDetektReportFile())
@ -50,11 +59,39 @@ class DetektLinter : Linter {
}
}
source = getSources(extension.excludes)
val diffsBranch = properties[ONLY_DIFFS_FLAG] as? String
source = getSources(extension.excludes, diffsBranch, project)
}
}
}
private fun getSources(excludes: String, diffsBranch: String?, project: Project): FileTree = when (diffsBranch) {
null -> project.getSources(excludes)
else -> getGitDiffFiles(excludes, diffsBranch, project)
}
private fun getGitDiffFiles(excludes: String, diffsBranch: String, project: Project): FileTree {
val getGitDiffsCommand = if (diffsBranch.isEmpty()) {
GET_GIT_DIFFS_COMMAND
} else {
GET_GIT_DIFFS_COMMAND.plus(" --merge-base $diffsBranch")
}
val gitDiffs = getGitDiffsCommand.runCommand()
if (gitDiffs.isNullOrEmpty()) {
project.logger.error("$TAG: Diffs are empty or specified branch or commit does not exists")
return project.files().asFileTree
}
val diffFiles = gitDiffs.lines()
.map { File(it) }
.filter { (it.extension == "kt" || it.extension == "java") && !excludes.contains(it.path) }
.toList()
return project.files(diffFiles).asFileTree
}
override fun getTaskNames(project: Project, buildType: String?): List<String> = listOf(":detekt")
private fun Project.getDetektReportFile() = file("${rootProject.buildDir}/reports/detekt.xml")

View File

@ -3,6 +3,7 @@ package static_analysis.plugins
import com.android.build.gradle.AppExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
import static_analysis.linters.AndroidLinter
import static_analysis.linters.CpdLinter
import static_analysis.linters.DetektLinter
import static_analysis.linters.Linter
@ -26,6 +27,23 @@ class StaticAnalysisAndroidPlugin : StaticAnalysisPlugin() {
buildVariant = applicationVariants.first { it.name.contains("Debug") }.name
)
}
/**
* Task to run detekt checks.
*
* @param -Ponly-diffs <branch or commit> if specified, only files modified
* relative to this branch or commit will be checked. If specified without value
* then current uncommited changes will be checked. If not specified all source files will be checked.
* @see DetektLinter.getGitDiffFiles, 'git diff' for more info.
* */
project.tasks.register("detektAnalysis") {
val detektLinter = linters.find { it is DetektLinter }
?: throw IllegalStateException("DetektLinter not found")
setupStaticAnalysisTask(
linters = listOf(detektLinter),
buildVariant = applicationVariants.first { it.name.contains("Debug") }.name
)
}
}
}
}
@ -34,8 +52,7 @@ class StaticAnalysisAndroidPlugin : StaticAnalysisPlugin() {
override fun createLinters(): List<Linter> = listOf(
DetektLinter(),
CpdLinter(),
//TODO temporary disable Android Linter to avoid FileNotFoundException when generating report
//AndroidLinter()
AndroidLinter()
)
}

View File

@ -0,0 +1,25 @@
package static_analysis.utils
import java.io.File
import java.io.IOException
import java.util.concurrent.TimeUnit
fun String.runCommand(
directoryToExecute: File? = null,
timeoutSec: Long = 30,
): String? {
return try {
val parts = this.split("\\s".toRegex())
val process = ProcessBuilder(*parts.toTypedArray())
.directory(directoryToExecute)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
process.waitFor(timeoutSec, TimeUnit.SECONDS)
process.inputStream.bufferedReader().readText()
} catch(e: IOException) {
e.printStackTrace()
null
}
}

View File

@ -0,0 +1,13 @@
android {
lint {
abortOnError false
checkAllWarnings true
warningsAsErrors false
checkDependencies true
htmlReport false
textReport false
xmlReport true
xmlOutput file("${rootProject.buildDir}/reports/lint-report.xml")
lintConfig file("${rootProject.ext["buildScriptsDir"]}/static_analysis_configs/lint.xml")
}
}

View File

@ -16,6 +16,9 @@
<!--All activities should have locked orientation-->
<issue id="LockedOrientationActivity" severity="ignore" />
<!-- TODO: Update Timber version. See this issue: https://github.com/JakeWharton/timber/issues/408 -->
<issue id="WrongTimberUsageDetector" severity="ignore" />
<issue id="AllowAllHostnameVerifier" severity="error" />
<issue id="InvalidUsesTagAttribute" severity="error" />
<issue id="MissingIntentFilterForMediaSearch" severity="error" />