Skip to content

Commit

Permalink
Resolves #31
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoBuransky committed Apr 8, 2016
1 parent 116972a commit 4baf9d9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion plugin/dev.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

SONAR_HOME=~/bin/sonarqube-5.1
SONAR_HOME=~/bin/sonarqube-5.4
PLUGIN_VERSION=5.1.2

mvn install
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.buransky.plugins.scoverage

import com.buransky.plugins.scoverage.language.Scala
import org.sonar.api.resources.Languages
import org.sonar.api.{Extension, ExtensionProvider, ServerExtension}

import scala.collection.JavaConversions._
import scala.collection.mutable.ListBuffer

class ScoverageExtensionProvider(languages: Languages) extends ExtensionProvider with ServerExtension {
override def provide(): java.util.List[Class[_ <: Extension]] = {
val result = ListBuffer[Class[_ <: Extension]]()

if (languages.get(Scala.key) == null) {
// Fix issue with multiple Scala plugins:
// https://github.com/RadoBuransky/sonar-scoverage-plugin/issues/31
result += classOf[Scala]
}

result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package com.buransky.plugins.scoverage

import com.buransky.plugins.scoverage.language.Scala
import com.buransky.plugins.scoverage.measure.ScalaMetrics
import com.buransky.plugins.scoverage.sensor.ScoverageSensor
import com.buransky.plugins.scoverage.widget.ScoverageWidget
Expand All @@ -34,12 +33,13 @@ import scala.collection.mutable.ListBuffer
* @author Rado Buransky
*/
class ScoveragePlugin extends SonarPlugin {
override def getExtensions: java.util.List[Class[_ <: Extension]] = ListBuffer(
classOf[Scala],
classOf[ScalaMetrics],
classOf[ScoverageSensor],
classOf[ScoverageWidget]
)
override def getExtensions: java.util.List[Class[_ <: Extension]] =
ListBuffer(
classOf[ScoverageExtensionProvider],
classOf[ScalaMetrics],
classOf[ScoverageSensor],
classOf[ScoverageWidget]
)

override val toString = getClass.getSimpleName
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,34 @@
*/
package com.buransky.plugins.scoverage.sensor

import java.io

import com.buransky.plugins.scoverage.language.Scala
import com.buransky.plugins.scoverage.measure.ScalaMetrics
import com.buransky.plugins.scoverage.pathcleaner.{BruteForceSequenceMatcher, PathSanitizer}
import com.buransky.plugins.scoverage.util.LogUtil
import com.buransky.plugins.scoverage.xml.XmlScoverageReportParser
import com.buransky.plugins.scoverage.{ CoveredStatement, DirectoryStatementCoverage, FileStatementCoverage, _ }
import org.sonar.api.batch.fs.{ FileSystem, InputFile, InputDir, InputPath }
import org.sonar.api.batch.{ CoverageExtension, Sensor, SensorContext }
import com.buransky.plugins.scoverage.{CoveredStatement, DirectoryStatementCoverage, FileStatementCoverage, _}
import org.sonar.api.batch.fs.{FileSystem, InputFile, InputPath}
import org.sonar.api.batch.{CoverageExtension, Sensor, SensorContext}
import org.sonar.api.config.Settings
import org.sonar.api.measures.{ CoreMetrics, CoverageMeasuresBuilder, Measure }
import org.sonar.api.resources.{ File, Project, Directory, Resource }
import org.sonar.api.measures.{CoverageMeasuresBuilder, Measure}
import org.sonar.api.resources.{Project, Resource}
import org.sonar.api.scan.filesystem.PathResolver
import org.sonar.api.utils.log.Loggers

import scala.collection.JavaConversions._
import com.buransky.plugins.scoverage.pathcleaner.BruteForceSequenceMatcher
import com.buransky.plugins.scoverage.pathcleaner.PathSanitizer

/**
* Main sensor for importing Scoverage report to Sonar.
*
* @author Rado Buransky
*/
class ScoverageSensor(settings: Settings, pathResolver: PathResolver, fileSystem: FileSystem, scala: Scala)
class ScoverageSensor(settings: Settings, pathResolver: PathResolver, fileSystem: FileSystem)
extends Sensor with CoverageExtension {
private val log = Loggers.get(classOf[ScoverageSensor])
protected val SCOVERAGE_REPORT_PATH_PROPERTY = "sonar.scoverage.reportPath"
protected lazy val scoverageReportParser: ScoverageReportParser = XmlScoverageReportParser()

override def shouldExecuteOnProject(project: Project): Boolean = fileSystem.languages().contains(scala.getKey)
override def shouldExecuteOnProject(project: Project): Boolean = fileSystem.languages().contains(Scala.key)

override def analyse(project: Project, context: SensorContext) {
scoverageReportPath match {
Expand Down Expand Up @@ -188,7 +185,7 @@ class ScoverageSensor(settings: Settings, pathResolver: PathResolver, fileSystem
val p = fileSystem.predicates()
Option(fileSystem.inputFile(p.and(
p.hasRelativePath(path),
p.hasLanguage(scala.getKey),
p.hasLanguage(Scala.key),
p.hasType(InputFile.Type.MAIN))))
} else {
Option(fileSystem.inputDir(pathResolver.relativeFile(fileSystem.baseDir(), path)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ class ScoverageSensorSpec extends FlatSpec with Matchers with MockitoSugar {
val settings = mock[Settings]
val pathResolver = mock[PathResolver]
val fileSystem = mock[FileSystem]
} with ScoverageSensor(settings, pathResolver, fileSystem, scala)
} with ScoverageSensor(settings, pathResolver, fileSystem)

}

0 comments on commit 4baf9d9

Please sign in to comment.