Skip to content

Commit

Permalink
Merge pull request #129 from codacy/fix/non-optional-sets
Browse files Browse the repository at this point in the history
bump: Bump codacy analysis core version
  • Loading branch information
lolgab authored Sep 14, 2020
2 parents c7b81c7 + fdeabdc commit c5a194a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scalaVersion := "2.12.10"
fork in run := true
cancelable in Global := true

libraryDependencies ++= Seq("com.codacy" %% "codacy-analysis-core" % "3.2.0",
libraryDependencies ++= Seq("com.codacy" %% "codacy-analysis-core" % "3.3.7",
"com.lihaoyi" %% "pprint" % "0.5.7",
"org.wvlet.airframe" %% "airframe-log" % "19.12.4",
codacy.libs.scalatest)
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/codacy/plugins/test/ITest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.codacy.analysis.core.model.{FileError, Issue, Pattern, ToolResult}
import com.codacy.plugins.api._
import com.codacy.plugins.api.languages.{Language, Languages}
import com.codacy.plugins.results.traits.DockerTool
import com.codacy.plugins.utils.DockerHelper
import wvlet.log.LogSupport

final case class DockerImage(name: String, version: String) {
Expand Down Expand Up @@ -53,8 +54,9 @@ trait ITest extends LogSupport {
prefix = "",
needsCompilation = false,
hasUIConfiguration = true) {
override val dockerTag: String = dockerImageVersion
override val dockerImageName: String = dockerImageFor(Option(dockerImageVersion))
override val dockerImageName = s"${dockerImage.name}:${dockerImageVersion}"

override def toolVersion(dockerHelper: DockerHelper): Option[String] = Some(dockerImageVersion)
}
}

Expand Down
26 changes: 14 additions & 12 deletions src/main/scala/codacy/plugins/test/JsonTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,29 @@ object JsonTests extends ITest {
val dockerToolDocumentation: DockerToolDocumentation =
readDockerToolDocumentation(docsDirectory.toScala / DockerHelpers.testsDirectoryName, dockerImage)

dockerToolDocumentation.spec.fold(error("Could not read /docs/patterns.json successfully")) { _ =>
dockerToolDocumentation.toolSpecification.fold(error("Could not read /docs/patterns.json successfully")) { _ =>
debug("Read /docs/patterns.json successfully")
}

dockerToolDocumentation.descriptions.fold(error("Could not read /docs/description/description.json successfully")) {
descriptions =>
debug("Read /docs/description/description.json successfully")
descriptions.foreach { patternDescription =>
patternDescription.explanation.fold(
error(s"Could not read /docs/description/${patternDescription.patternId}.md")
) { _ =>
debug(s"Read /docs/description/${patternDescription.patternId}.md successfully")
}
dockerToolDocumentation.patternDescriptions.fold(
error("Could not read /docs/description/description.json successfully")
) { descriptions =>
debug("Read /docs/description/description.json successfully")
descriptions.foreach { patternDescription =>
patternDescription.explanation.fold(
error(s"Could not read /docs/description/${patternDescription.patternId}.md")
) { _ =>
debug(s"Read /docs/description/${patternDescription.patternId}.md successfully")
}
}
}

(dockerToolDocumentation.spec, dockerToolDocumentation.descriptions) match {
(dockerToolDocumentation.toolSpecification, dockerToolDocumentation.patternDescriptions) match {
case (Some(tool), Some(descriptions)) =>
val diffResult = new CollectionHelper[Pattern.Specification, PatternDescription, String](tool.patterns.toSeq,
descriptions.toSeq)({
pattern =>
val parameters = pattern.parameters.getOrElse(Seq.empty).map(_.name.value).toSeq.sorted
val parameters = pattern.parameters.map(_.name.value).toSeq.sorted
generateUniquePatternSignature(pattern.patternId.value, parameters)
}, { description =>
val parameters = description.parameters.getOrElse(Seq.empty).map(_.name.value).toSeq.sorted
Expand Down Expand Up @@ -107,6 +108,7 @@ object JsonTests extends ITest {
private def readDockerToolDocumentation(testsDirectory: File, dockerImage: DockerImage) = {
val languages = findLanguages(testsDirectory.toJava, dockerImage)
val dockerTool = createDockerTool(languages, dockerImage)

new DockerToolDocumentation(dockerTool, new BinaryDockerHelper(useCachedDocs = false))
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/scala/codacy/plugins/test/PatternTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ object PatternTests extends ITest with CustomMatchers {
val testsDirectory = docsDirectory.toScala / DockerHelpers.testsDirectoryName
val languages = findLanguages(testsDirectory.toJava, dockerImage)
val dockerTool = createDockerTool(languages, dockerImage)
val toolDocumentation = new DockerToolDocumentation(dockerTool, new BinaryDockerHelper(useCachedDocs = false))
val dockerRunner = new BinaryDockerRunner[Result](dockerTool)
val runner = new ToolRunner(dockerTool, toolDocumentation, dockerRunner)
val dockerToolDocumentation = new DockerToolDocumentation(dockerTool, new BinaryDockerHelper())

val specOpt = dockerToolDocumentation.toolSpecification
val runner =
new ToolRunner(dockerToolDocumentation.toolSpecification, dockerToolDocumentation.toolPrefix, dockerRunner)
val tools = languages.map(new core.tools.Tool(runner, DockerRunner.defaultRunTimeout)(dockerTool, _))

val testFiles = new TestFilesParser(testsDirectory.toJava).getTestFiles
Expand All @@ -42,7 +45,7 @@ object PatternTests extends ITest with CustomMatchers {
tools
.filter(_.languageToRun.name.equalsIgnoreCase(testFile.language.toString))
.map { tool =>
val analysisResultTry = analyseFile(toolDocumentation.spec, testsDirectory, testFile, tool)
val analysisResultTry = analyseFile(specOpt, testsDirectory, testFile, tool)
(testFile, analysisResultTry.map(matches => (matches, beEqualTo(testFile.matches).apply(matches))))
}
}
Expand All @@ -55,7 +58,7 @@ object PatternTests extends ITest with CustomMatchers {
debug(s"""- $filename should have ${testFile.matches.length} matches with patterns: ${testFile.enabledPatterns
.map(_.name)
.mkString(", ")}
| + ${matches.size} matches found in lines: ${matches
| + ${matches.size} matches found in lines: ${matches
.map(_.line)
.to[Seq]
.sorted
Expand Down
22 changes: 12 additions & 10 deletions src/main/scala/codacy/plugins/test/PluginsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ object PluginsTests extends ITest {

val languages = findLanguages(testsDirectory.toJava, dockerImage)
val dockerTool = createDockerTool(languages, dockerImage)
val dockerToolDocumentation = new DockerToolDocumentation(dockerTool, new BinaryDockerHelper(useCachedDocs = false))
val specOpt = dockerToolDocumentation.spec

val dockerRunner = new BinaryDockerRunner[Result](dockerTool)
val runner = new ToolRunner(dockerTool, dockerToolDocumentation, dockerRunner)
val dockerToolDocumentation = new DockerToolDocumentation(dockerTool, new BinaryDockerHelper())

val specOpt = dockerToolDocumentation.toolSpecification
val runner =
new ToolRunner(dockerToolDocumentation.toolSpecification, dockerToolDocumentation.toolPrefix, dockerRunner)

specOpt.forall { spec =>
debug(s" + ${spec.name} should find results for all patterns")

val patterns: Set[Pattern] = spec.patterns.map(
p =>
core.model.Pattern(p.patternId.value, p.parameters.fold(Set.empty[core.model.Parameter])(_.map {
parameterSpec =>
core.model.Parameter(parameterSpec.name.toString(), parameterSpec.default.toString)
}(collection.breakOut)))
core.model.Pattern(p.patternId.value, p.parameters.map { parameterSpec =>
core.model.Parameter(parameterSpec.name.toString(), parameterSpec.default.toString)
}(collection.breakOut))
)(collection.breakOut)
val codacyCfg = CodacyCfg(patterns)

Expand Down Expand Up @@ -66,9 +68,9 @@ object PluginsTests extends ITest {
case Success(missingPatterns) =>
if (missingPatterns.nonEmpty) {
error(s"""
|Some patterns are not tested on plugin ${spec.name}
|-> Missing patterns:
|${missingPatterns.mkString(", ")}
|Some patterns are not tested on plugin ${spec.name}
|-> Missing patterns:
|${missingPatterns.mkString(", ")}
""".stripMargin)
false
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ object MultipleTests extends ITest {
val srcDir = testDirectory / "src"
// on multiple tests, the language is not validated but required. We used Scala.
val dockerTool = createDockerTool(Set(Languages.Scala), dockerImage)
val toolDocumentation = new DockerToolDocumentation(dockerTool, new BinaryDockerHelper(useCachedDocs = false))
val dockerRunner = new BinaryDockerRunner[Result](dockerTool)
val runner = new ToolRunner(dockerTool, toolDocumentation, dockerRunner)
val dockerToolDocumentation = new DockerToolDocumentation(dockerTool, new BinaryDockerHelper())

val runner =
new ToolRunner(dockerToolDocumentation.toolSpecification, dockerToolDocumentation.toolPrefix, dockerRunner)
val resultFile = testDirectory / "results.xml"
val resultFileXML = XML.loadFile(resultFile.toJava)
val expectedResults = CheckstyleFormatParser.parseResultsXml(resultFileXML)
Expand Down

0 comments on commit c5a194a

Please sign in to comment.