From 262427bc6da5facbbe8325370bed6f1d36672902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Cort=C3=AAs?= Date: Thu, 15 Feb 2024 13:51:49 +0000 Subject: [PATCH] fix: generate .codacyrc with tool shortname in PatternTests --- .../scala/codacy/plugins/test/ITest.scala | 54 +++++++++---------- .../codacy/plugins/test/PatternTests.scala | 7 ++- .../test/ExampleDuplicationToolTests.scala | 4 +- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/main/scala/codacy/plugins/test/ITest.scala b/src/main/scala/codacy/plugins/test/ITest.scala index 18b3a6f..bd1fa6c 100644 --- a/src/main/scala/codacy/plugins/test/ITest.scala +++ b/src/main/scala/codacy/plugins/test/ITest.scala @@ -3,6 +3,7 @@ package codacy.plugins.test import better.files._ import com.codacy.analysis.core.model.{FileError, Issue, ParameterSpec, Pattern, PatternSpec, ToolResult, ToolSpec} import com.codacy.analysis.core.tools.FullToolSpec +import com.codacy.plugins.api import com.codacy.plugins.api._ import com.codacy.plugins.api.languages.{Language, Languages} import com.codacy.plugins.results.traits.DockerToolDocumentation @@ -34,33 +35,12 @@ trait ITest extends LogSupport { languagesFromProperties.getOrElse(languagesFromFiles) } - protected def createToolSpec(languages: Set[Language], dockerImage: DockerImage): ToolSpec = { - val dockerImageName = dockerImage.name - val dockerImageVersion = dockerImage.version - - new ToolSpec(uuid = dockerImageName, - dockerImage = s"${dockerImage.name}:${dockerImageVersion}", - version = dockerImageVersion, - languages = languages, - name = dockerImageName, - shortName = dockerImageName, - documentationUrl = Some(""), - sourceCodeUrl = Some(""), - prefix = "", - needsCompilation = false, - hasConfigFile = true, - standalone = false, - hasUIConfiguration = true, - isDefault = true, - configFilenames = Set.empty) - } - - protected def createFullToolSpec(toolSpec: ToolSpec, - dockerToolDocumentation: DockerToolDocumentation): FullToolSpec = { + protected def createFullToolSpec(toolSpec: api.results.Tool.Specification, + dockerToolDocumentation: DockerToolDocumentation, + languages: Set[Language], + dockerImage: DockerImage): FullToolSpec = { val patternDescriptions = dockerToolDocumentation.patternDescriptions.getOrElse(Set.empty) - val patterns = dockerToolDocumentation.toolSpecification - .map(_.patterns) - .getOrElse(Seq.empty) + val patterns = toolSpec.patterns .flatMap { pattern => patternDescriptions .find(_.patternId == pattern.patternId) @@ -69,7 +49,27 @@ trait ITest extends LogSupport { } }(collection.breakOut) - FullToolSpec(toolSpec, patterns) + FullToolSpec(toToolSpec(toolSpec, languages, dockerImage), patterns) + } + + private def toToolSpec(toolSpec: api.results.Tool.Specification, + languages: Set[Language], + dockerImage: DockerImage): ToolSpec = { + ToolSpec(toolSpec.name.value, + dockerImage.toString, + isDefault = true, + dockerImage.version, + languages, + toolSpec.name.value, + toolSpec.name.value, + Option.empty, + Option.empty, + prefix = "", + needsCompilation = false, + hasConfigFile = true, + Set.empty, + standalone = false, + hasUIConfiguration = true) } private def merge(p: results.Pattern.Specification, pd: PatternDescription): PatternSpec = { diff --git a/src/main/scala/codacy/plugins/test/PatternTests.scala b/src/main/scala/codacy/plugins/test/PatternTests.scala index 6b75ff5..0a7c93e 100644 --- a/src/main/scala/codacy/plugins/test/PatternTests.scala +++ b/src/main/scala/codacy/plugins/test/PatternTests.scala @@ -22,11 +22,10 @@ object PatternTests extends ITest with CustomMatchers { val testsDirectory = docsDirectory.toScala / DockerHelpers.testsDirectoryName val languages = findLanguages(testsDirectory.toJava) val dockerTool = new IDocker(dockerImage.toString()) {} - val toolSpec = createToolSpec(languages, dockerImage) val dockerToolDocumentation = new DockerToolDocumentation(dockerTool, new BinaryDockerHelper()) - val toolFullSpec = createFullToolSpec(toolSpec, dockerToolDocumentation) + val toolSpecOpt = dockerToolDocumentation.toolSpecification + val toolFullSpec = createFullToolSpec(toolSpecOpt.get, dockerToolDocumentation, languages, dockerImage) - val specOpt = dockerToolDocumentation.toolSpecification val tools = languages.map(new core.tools.Tool(toolFullSpec, _, DockerRunner.defaultRunTimeout)) val testFiles = new TestFilesParser(testsDirectory.toJava).getTestFiles @@ -42,7 +41,7 @@ object PatternTests extends ITest with CustomMatchers { tools .filter(_.languageToRun.name.equalsIgnoreCase(testFile.language.toString)) .map { tool => - val analysisResultTry = analyseFile(specOpt, testsDirectory, testFile, tool) + val analysisResultTry = analyseFile(toolSpecOpt, testsDirectory, testFile, tool) (testFile, analysisResultTry.map(matches => (matches, beEqualTo(testFile.matches).apply(matches)))) } } diff --git a/src/test/scala/codacy/plugins/test/ExampleDuplicationToolTests.scala b/src/test/scala/codacy/plugins/test/ExampleDuplicationToolTests.scala index 24e6304..a69c4d7 100644 --- a/src/test/scala/codacy/plugins/test/ExampleDuplicationToolTests.scala +++ b/src/test/scala/codacy/plugins/test/ExampleDuplicationToolTests.scala @@ -5,9 +5,9 @@ import org.scalatest.funsuite.AnyFunSuite class ExampleDuplicationToolTests extends AnyFunSuite { test("[ExampleDuplicationTool] tests should pass") { - DockerTest.main(Array("pattern", "codacy/codacy-duplication-example-tool:latest")) + DockerTest.main(Array("duplication", "codacy/codacy-duplication-example-tool:latest")) } test("[ExampleDuplicationTool] tests with wrong test name should throw exception") { - intercept[Exception](DockerTest.main(Array("patern", "codacy/codacy-duplication-example-tool:latest"))) + intercept[Exception](DockerTest.main(Array("duplicaion", "codacy/codacy-duplication-example-tool:latest"))) } }