Skip to content

Commit

Permalink
Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoBuransky committed Feb 7, 2014
1 parent 3559692 commit 4804dc9
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
import java.util.ArrayList;
import java.util.List;

/**
* Plugin entry point.
*
* @author Rado Buransky
*/
public class ScoveragePlugin extends SonarPlugin {

public List<Class<? extends Extension>> getExtensions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

import org.sonar.api.resources.AbstractLanguage;

/**
* Scala language.
*
* @author Rado Buransky
*/
public class Scala extends AbstractLanguage {

public static final Scala INSTANCE = new Scala();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import java.util.Arrays;
import java.util.List;

/**
* Statement coverage metric definition.
*
* @author Rado Buransky
*/
public final class ScalaMetrics implements Metrics {
private static final String STATEMENT_COVERAGE_KEY = "scoverage";
public static final Metric STATEMENT_COVERAGE = new Metric.Builder(STATEMENT_COVERAGE_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Resource;

/**
* Scala source code file resource.
*
* @author Rado Buransky
*/
public class ScalaFile extends Resource {
private final File file;
private ScalaDirectory parent;
private SingleDirectory parent;

public ScalaFile(String key) {
if (key == null)
Expand Down Expand Up @@ -67,9 +72,9 @@ public String getQualifier() {
}

@Override
public ScalaDirectory getParent() {
public SingleDirectory getParent() {
if (parent == null) {
parent = new ScalaDirectory(file.getParent().getKey());
parent = new SingleDirectory(file.getParent().getKey());
}
return parent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Resource;

public class ScalaDirectory extends Directory {
/**
* Single directory in file system. Unlike org.sonar.api.resources.Directory that can represent
* a chain of directories.
*
* @author Rado Buransky
*/
public class SingleDirectory extends Directory {
private final String name;
private final ScalaDirectory parent;
private final SingleDirectory parent;

public ScalaDirectory(String key) {
public SingleDirectory(String key) {
super(key);

int i = getKey().lastIndexOf(SEPARATOR);
if (i > 0) {
parent = new ScalaDirectory(key.substring(0, i));
parent = new SingleDirectory(key.substring(0, i));
name = key.substring(i + 1);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.buransky.plugins.scoverage.*;
import com.buransky.plugins.scoverage.language.Scala;
import com.buransky.plugins.scoverage.measure.ScalaMetrics;
import com.buransky.plugins.scoverage.resource.ScalaDirectory;
import com.buransky.plugins.scoverage.resource.ScalaFile;
import com.buransky.plugins.scoverage.xml.XmlScoverageReportParser$;
import org.slf4j.Logger;
Expand All @@ -31,17 +30,18 @@
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.CoverageMeasuresBuilder;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.*;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import scala.collection.JavaConversions;
import org.sonar.api.scan.filesystem.PathResolver;

import java.util.HashMap;
import java.util.Map;

/**
* Main sensor for importing Scoverage report to Sonar.
*
* @author Rado Buransky
*/
public class ScoverageSensor implements Sensor, CoverageExtension {
private static final Logger log = LoggerFactory.getLogger(ScoverageSensor.class);
private final ScoverageReportParser scoverageReportParser;
Expand Down Expand Up @@ -107,7 +107,7 @@ private void processDirectory(DirectoryStatementCoverage directoryCoverage, Sens
String parentDirectory) {
String currentDirectory = appendFilePath(parentDirectory, directoryCoverage.name());

ScalaDirectory directory = new ScalaDirectory(currentDirectory);
com.buransky.plugins.scoverage.resource.SingleDirectory directory = new com.buransky.plugins.scoverage.resource.SingleDirectory(currentDirectory);
context.saveMeasure(directory, createStatementCoverage(directoryCoverage.rate()));

log("Process directory [" + directory.getKey() + ", " + directoryCoverage.rate() + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@

import java.io.IOException;

/**
* Imports Scala source code files to Sonar.
*
* @author Rado Buransky
*/
@Phase(name = Name.PRE)
public class ScoverageSourceImporterSensor implements Sensor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
import org.sonar.api.web.AbstractRubyTemplate;
import org.sonar.api.web.RubyRailsWidget;

/**
* UI widget that can be added to the main dashboard to display overall statement coverage for the project.
*
* @author Rado Buransky
*/
public class ScoverageWidget extends AbstractRubyTemplate implements RubyRailsWidget {

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@
*/
package com.buransky.plugins.scoverage

/**
* Interface for Scoverage report parser.
*
* @author Rado Buransky
*/
trait ScoverageReportParser {
def parse(reportFilePath: String): ProjectStatementCoverage
}

/**
* Common Scoverage exception.
*
* @author Rado Buransky
*/
case class ScoverageException(message: String, source: Throwable = null)
extends Exception(message, source)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package com.buransky.plugins.scoverage
/**
* Statement coverage represents rate at which are statements of a certain source code unit
* being covered by tests.
*
* @author Rado Buransky
*/
sealed trait StatementCoverage {
/**
Expand Down Expand Up @@ -59,23 +61,40 @@ trait NodeStatementCoverage extends StatementCoverage {
/**
* Root node. In multi-module projects it can contain other ProjectStatementCoverage
* elements as children.
*
* @param name Name of the project or module.
* @param children
*/
case class ProjectStatementCoverage(name: String, children: Iterable[StatementCoverage])
extends NodeStatementCoverage

/**
* Physical directory in file system.
*/
case class DirectoryStatementCoverage(name: String, children: Iterable[StatementCoverage])
extends NodeStatementCoverage

/**
* Scala source code file.
*/
case class FileStatementCoverage(name: String, statementCount: Int, coveredStatementsCount: Int,
statements: Iterable[CoveredStatement]) extends StatementCoverage

/**
* Position a Scala source code file.
*/
case class StatementPosition(line: Int, pos: Int)

/**
* Coverage information about the Scala statement.
*
* @param start Starting position of the statement.
* @param end Ending position of the statement.
* @param hitCount How many times has the statement been hit by unit tests. Zero means
* that the statement is not covered.
*/
case class CoveredStatement(start: StatementPosition, end: StatementPosition, hitCount: Int)

/**
* Aggregated statement coverage for a given source code line.
*/
case class CoveredLine(line: Int, hitCount: Int)

object StatementCoverage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import com.buransky.plugins.scoverage.FileStatementCoverage
import com.buransky.plugins.scoverage.DirectoryStatementCoverage
import scala.io.Source

/**
* Stub with some dummy data so that we don't have to parse XML for testing.
*
* @author Rado Buransky
*/
class StubScoverageReportParser extends ScoverageReportParser {
def parse(reportFilePath: String): ProjectStatementCoverage = {
val errorCodeFile = FileStatementCoverage("ErrorCode.scala", 17, 13,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import scala.collection.mutable
import scala.annotation.tailrec
import java.io.File

/**
* Scoverage XML parser based on ConstructingParser provided by standard Scala library.
*
* @author Rado Buransky
*/
class XmlScoverageReportConstructingParser(source: Source) extends ConstructingParser(source, false) {
private val log = Logger.getLogger(classOf[XmlScoverageReportConstructingParser])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import scala.io.Source
import com.buransky.plugins.scoverage.{ProjectStatementCoverage, ScoverageReportParser, ScoverageException}
import org.apache.log4j.Logger

/**
* Bridge between parser implementation and coverage provider.
*
* @author Rado Buransky
*/
class XmlScoverageReportParser extends ScoverageReportParser {
private val log = Logger.getLogger(classOf[XmlScoverageReportParser])

Expand Down

0 comments on commit 4804dc9

Please sign in to comment.