Skip to content

Commit

Permalink
feat(coverage): Enable scoverage reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Augustin Borsu committed May 1, 2016
1 parent c2f1d9e commit 371cfc8
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 294 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ This plugin is not an evolution from the legacy sonar-scala-plugin of which vers
The previous plugin used the scala compiler to create its metrics which had the disadvantage of requiring a specific plugin per scala version.
Instead, we are using the [scala-ide/scalariform](https://github.com/scala-ide/scalariform) library to parse the source code in a version independent way.

# TODO
# TODO (by priority)
* Add property to sepcify scala version (currently defaults to 2.11.8)
* Integrate coverage metrics
* Integrate scalawarts
* Optimize scalastyle integration (currently two seperate analysers)
* Add Complexity metric on file (use the one in scalastyle)
* remove dependency on commons-io (Currently only needed by BruteForceSequenceMatcher)
* Uncomment ScoverageSensorSpec
* Integrate other java compatible code quality tools
* Optimize sensors i.e. (scalastyle and base both read and parse source files.)
...

# Credits
Expand Down
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>

<!-- unit tests -->
<dependency>
<groupId>org.scalatest</groupId>
Expand Down Expand Up @@ -133,7 +145,14 @@
</dependencies>

<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<plugins>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>1.1.1</version>
</plugin>

<!-- disable surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
3 changes: 3 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ sonar.exclusions=src/test/resources/**,

# Encoding of the source files
sonar.sourceEncoding=UTF-8

# Code Coverage reports
sonar.scoverage.reportPath=target/scoverage.xml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package com.buransky.plugins.scoverage.pathcleaner

import java.io.File
import org.apache.commons.io.FileUtils
import org.apache.commons.io.FileUtils
import BruteForceSequenceMatcher._
import com.buransky.plugins.scoverage.util.PathUtil
import scala.collection.JavaConversions._
Expand All @@ -37,14 +36,14 @@ object BruteForceSequenceMatcher {
/**
* Helper that allows to convert a report path into a source folder relative path by testing it against
* the tree of source files.
*
*
* Assumes that all report paths of a given report have a common root. Dependent of the scoverage
* report this root is either something outside the actual project (absolute path), the base dir of the project
* (report path relative to base dir) or some sub folder of the project.
*
*
* By reverse mapping a report path against the tree of all file children of the source folder the correct filesystem file
* can be found and the report path can be converted into a source dir relative path. *
*
* can be found and the report path can be converted into a source dir relative path. *
*
* @author Michael Zinsmaier
*/
class BruteForceSequenceMatcher(baseDir: File, sourcePath: String) extends PathSanitizer {
Expand All @@ -54,27 +53,27 @@ class BruteForceSequenceMatcher(baseDir: File, sourcePath: String) extends PathS
require(sourceDir.isDirectory)

private val log = Loggers.get(classOf[BruteForceSequenceMatcher])
private val sourcePathLength = PathUtil.splitPath(sourceDir.getAbsolutePath).size
private val sourcePathLength = PathUtil.splitPath(sourceDir.getAbsolutePath).size
private val filesMap = initFilesMap()


def getSourceRelativePath(reportPath: PathSeq): Option[PathSeq] = {
// match with file system map of files
// match with file system map of files
val relPathOption = for {
absPathCandidates <- filesMap.get(reportPath.last)
path <- absPathCandidates.find(absPath => absPath.endsWith(reportPath))
} yield path.drop(sourcePathLength)

relPathOption
}

// mock able helpers that allow us to remove the dependency to the real file system during tests

private[pathcleaner] def initSourceDir(): File = {
val sourceDir = new File(baseDir, sourcePath)
sourceDir
}

private[pathcleaner] def initFilesMap(): Map[String, Seq[PathSeq]] = {
val srcFiles = FileUtils.iterateFiles(sourceDir, extensions, true)
val paths = srcFiles.map(file => PathUtil.splitPath(file.getAbsolutePath)).toSeq
Expand All @@ -83,4 +82,4 @@ class BruteForceSequenceMatcher(baseDir: File, sourcePath: String) extends PathS
paths.groupBy(path => path.last)
}

}
}
14 changes: 10 additions & 4 deletions src/main/scala/com/sagacify/sonar/scala/ScalaPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package com.sagacify.sonar.scala
import scala.collection.JavaConversions._
import scala.collection.mutable.ListBuffer

import com.buransky.plugins.scoverage.measure.ScalaMetrics
import com.buransky.plugins.scoverage.sensor.ScoverageSensor
import com.buransky.plugins.scoverage.widget.ScoverageWidget
import com.ncredinburgh.sonar.scalastyle.ScalastyleQualityProfile
import com.ncredinburgh.sonar.scalastyle.ScalastyleRepository
import com.ncredinburgh.sonar.scalastyle.ScalastyleSensor
import org.sonar.api.config.Settings
import org.sonar.api.Extension
import org.sonar.api.resources.AbstractLanguage
import org.sonar.api.SonarPlugin
import scalariform.lexer.ScalaLexer
import scalariform.lexer.Token
import com.ncredinburgh.sonar.scalastyle.ScalastyleRepository
import com.ncredinburgh.sonar.scalastyle.ScalastyleQualityProfile
import com.ncredinburgh.sonar.scalastyle.ScalastyleSensor

/**
* Defines Scala as a language for SonarQube.
Expand Down Expand Up @@ -40,7 +43,10 @@ class ScalaPlugin extends SonarPlugin {
classOf[ScalaSensor],
classOf[ScalastyleRepository],
classOf[ScalastyleQualityProfile],
classOf[ScalastyleSensor]
classOf[ScalastyleSensor],
classOf[ScalaMetrics],
classOf[ScoverageSensor],
classOf[ScoverageWidget]
)

override val toString = getClass.getSimpleName
Expand Down
Loading

0 comments on commit 371cfc8

Please sign in to comment.