Skip to content

Commit 262427b

Browse files
committed
fix: generate .codacyrc with tool shortname in PatternTests
1 parent 0b3fc84 commit 262427b

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

src/main/scala/codacy/plugins/test/ITest.scala

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package codacy.plugins.test
33
import better.files._
44
import com.codacy.analysis.core.model.{FileError, Issue, ParameterSpec, Pattern, PatternSpec, ToolResult, ToolSpec}
55
import com.codacy.analysis.core.tools.FullToolSpec
6+
import com.codacy.plugins.api
67
import com.codacy.plugins.api._
78
import com.codacy.plugins.api.languages.{Language, Languages}
89
import com.codacy.plugins.results.traits.DockerToolDocumentation
@@ -34,33 +35,12 @@ trait ITest extends LogSupport {
3435
languagesFromProperties.getOrElse(languagesFromFiles)
3536
}
3637

37-
protected def createToolSpec(languages: Set[Language], dockerImage: DockerImage): ToolSpec = {
38-
val dockerImageName = dockerImage.name
39-
val dockerImageVersion = dockerImage.version
40-
41-
new ToolSpec(uuid = dockerImageName,
42-
dockerImage = s"${dockerImage.name}:${dockerImageVersion}",
43-
version = dockerImageVersion,
44-
languages = languages,
45-
name = dockerImageName,
46-
shortName = dockerImageName,
47-
documentationUrl = Some(""),
48-
sourceCodeUrl = Some(""),
49-
prefix = "",
50-
needsCompilation = false,
51-
hasConfigFile = true,
52-
standalone = false,
53-
hasUIConfiguration = true,
54-
isDefault = true,
55-
configFilenames = Set.empty)
56-
}
57-
58-
protected def createFullToolSpec(toolSpec: ToolSpec,
59-
dockerToolDocumentation: DockerToolDocumentation): FullToolSpec = {
38+
protected def createFullToolSpec(toolSpec: api.results.Tool.Specification,
39+
dockerToolDocumentation: DockerToolDocumentation,
40+
languages: Set[Language],
41+
dockerImage: DockerImage): FullToolSpec = {
6042
val patternDescriptions = dockerToolDocumentation.patternDescriptions.getOrElse(Set.empty)
61-
val patterns = dockerToolDocumentation.toolSpecification
62-
.map(_.patterns)
63-
.getOrElse(Seq.empty)
43+
val patterns = toolSpec.patterns
6444
.flatMap { pattern =>
6545
patternDescriptions
6646
.find(_.patternId == pattern.patternId)
@@ -69,7 +49,27 @@ trait ITest extends LogSupport {
6949
}
7050
}(collection.breakOut)
7151

72-
FullToolSpec(toolSpec, patterns)
52+
FullToolSpec(toToolSpec(toolSpec, languages, dockerImage), patterns)
53+
}
54+
55+
private def toToolSpec(toolSpec: api.results.Tool.Specification,
56+
languages: Set[Language],
57+
dockerImage: DockerImage): ToolSpec = {
58+
ToolSpec(toolSpec.name.value,
59+
dockerImage.toString,
60+
isDefault = true,
61+
dockerImage.version,
62+
languages,
63+
toolSpec.name.value,
64+
toolSpec.name.value,
65+
Option.empty,
66+
Option.empty,
67+
prefix = "",
68+
needsCompilation = false,
69+
hasConfigFile = true,
70+
Set.empty,
71+
standalone = false,
72+
hasUIConfiguration = true)
7373
}
7474

7575
private def merge(p: results.Pattern.Specification, pd: PatternDescription): PatternSpec = {

src/main/scala/codacy/plugins/test/PatternTests.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ object PatternTests extends ITest with CustomMatchers {
2222
val testsDirectory = docsDirectory.toScala / DockerHelpers.testsDirectoryName
2323
val languages = findLanguages(testsDirectory.toJava)
2424
val dockerTool = new IDocker(dockerImage.toString()) {}
25-
val toolSpec = createToolSpec(languages, dockerImage)
2625
val dockerToolDocumentation = new DockerToolDocumentation(dockerTool, new BinaryDockerHelper())
27-
val toolFullSpec = createFullToolSpec(toolSpec, dockerToolDocumentation)
26+
val toolSpecOpt = dockerToolDocumentation.toolSpecification
27+
val toolFullSpec = createFullToolSpec(toolSpecOpt.get, dockerToolDocumentation, languages, dockerImage)
2828

29-
val specOpt = dockerToolDocumentation.toolSpecification
3029
val tools = languages.map(new core.tools.Tool(toolFullSpec, _, DockerRunner.defaultRunTimeout))
3130

3231
val testFiles = new TestFilesParser(testsDirectory.toJava).getTestFiles
@@ -42,7 +41,7 @@ object PatternTests extends ITest with CustomMatchers {
4241
tools
4342
.filter(_.languageToRun.name.equalsIgnoreCase(testFile.language.toString))
4443
.map { tool =>
45-
val analysisResultTry = analyseFile(specOpt, testsDirectory, testFile, tool)
44+
val analysisResultTry = analyseFile(toolSpecOpt, testsDirectory, testFile, tool)
4645
(testFile, analysisResultTry.map(matches => (matches, beEqualTo(testFile.matches).apply(matches))))
4746
}
4847
}

src/test/scala/codacy/plugins/test/ExampleDuplicationToolTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import org.scalatest.funsuite.AnyFunSuite
55

66
class ExampleDuplicationToolTests extends AnyFunSuite {
77
test("[ExampleDuplicationTool] tests should pass") {
8-
DockerTest.main(Array("pattern", "codacy/codacy-duplication-example-tool:latest"))
8+
DockerTest.main(Array("duplication", "codacy/codacy-duplication-example-tool:latest"))
99
}
1010
test("[ExampleDuplicationTool] tests with wrong test name should throw exception") {
11-
intercept[Exception](DockerTest.main(Array("patern", "codacy/codacy-duplication-example-tool:latest")))
11+
intercept[Exception](DockerTest.main(Array("duplicaion", "codacy/codacy-duplication-example-tool:latest")))
1212
}
1313
}

0 commit comments

Comments
 (0)