Skip to content

Commit 6d9a113

Browse files
committed
Merge branch 'release/1.0'
2 parents f41e6e4 + ad591bf commit 6d9a113

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1058
-593
lines changed

build.sbt

Lines changed: 0 additions & 80 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

project/Scoverage.scala

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import sbt.Keys._
2+
import sbt._
3+
4+
object Scoverage extends Build {
5+
6+
val Org = "org.scoverage"
7+
val Version = "1.0.0.BETA2"
8+
val Scala = "2.11.4"
9+
val Slf4jVersion = "1.7.7"
10+
val ScalatestVersion = "2.2.2"
11+
12+
lazy val LocalTest = config("local") extend Test
13+
14+
val appSettings = Seq(
15+
version := Version,
16+
organization := Org,
17+
scalaVersion := Scala,
18+
crossScalaVersions := Seq("2.10.4", "2.11.4"),
19+
fork in Test := false,
20+
publishMavenStyle := true,
21+
publishArtifact in Test := false,
22+
parallelExecution in Test := false,
23+
scalacOptions := Seq("-unchecked", "-deprecation", "-feature", "-encoding", "utf8"),
24+
resolvers := ("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2") +: resolvers.value,
25+
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1),
26+
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8"),
27+
javacOptions := Seq("-source", "1.6", "-target", "1.6"),
28+
libraryDependencies ++= Seq(
29+
"org.joda" % "joda-convert" % "1.6" % "test",
30+
"joda-time" % "joda-time" % "2.3" % "test",
31+
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2" % "test",
32+
"org.mockito" % "mockito-all" % "1.9.5" % "test",
33+
"org.scalatest" %% "scalatest" % ScalatestVersion % "test"
34+
),
35+
publishTo <<= version {
36+
(v: String) =>
37+
val nexus = "https://oss.sonatype.org/"
38+
if (v.trim.endsWith("SNAPSHOT"))
39+
Some(Resolver.file("file", new File(Path.userHome.absolutePath + "/.m2/repository")))
40+
else
41+
Some("releases" at nexus + "service/local/staging/deploy/maven2")
42+
},
43+
pomExtra := {
44+
<url>https://github.com/scoverage/scalac-scoverage-plugin</url>
45+
<licenses>
46+
<license>
47+
<name>Apache 2</name>
48+
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
49+
<distribution>repo</distribution>
50+
</license>
51+
</licenses>
52+
<scm>
53+
<url>git@github.com:scoverage/scalac-scoverage-plugin.git</url>
54+
<connection>scm:git@github.com:scoverage/scalac-scoverage-plugin.git</connection>
55+
</scm>
56+
<developers>
57+
<developer>
58+
<id>sksamuel</id>
59+
<name>Stephen Samuel</name>
60+
<url>http://github.com/sksamuel</url>
61+
</developer>
62+
</developers>
63+
},
64+
pomIncludeRepository := {
65+
_ => false
66+
}
67+
)
68+
69+
lazy val root = Project("scalac-scoverage", file("."))
70+
.settings(name := "scalac-scoverage")
71+
.settings(appSettings: _*)
72+
.settings(publishArtifact := false)
73+
.aggregate(plugin, runtime)
74+
75+
lazy val runtime = Project("scalac-scoverage-runtime", file("scalac-scoverage-runtime"))
76+
.settings(name := "scalac-scoverage-runtime")
77+
.settings(appSettings: _*)
78+
79+
lazy val plugin = Project("scalac-scoverage-plugin", file("scalac-scoverage-plugin"))
80+
.settings(name := "scalac-scoverage-plugin")
81+
.dependsOn(runtime)
82+
.settings(appSettings: _*)
83+
.settings(libraryDependencies ++= Seq(
84+
"org.slf4j" % "slf4j-api" % Slf4jVersion,
85+
"commons-io" % "commons-io" % "2.4",
86+
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
87+
"org.scala-lang" % "scala-compiler" % scalaVersion.value
88+
)).settings(libraryDependencies ++= {
89+
CrossVersion.partialVersion(scalaVersion.value) match {
90+
case Some((2, scalaMajor)) if scalaMajor == 11 =>
91+
EnvSupport.setEnv("CrossBuildScalaVersion", "2.11.4")
92+
Seq("org.scala-lang.modules" %% "scala-xml" % "1.0.1")
93+
case _ =>
94+
EnvSupport.setEnv("CrossBuildScalaVersion", "2.10.4")
95+
Nil
96+
}
97+
})
98+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package scoverage

src/main/scala/scoverage/CoverageFilter.scala renamed to scalac-scoverage-plugin/src/main/scala/scoverage/CoverageFilter.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package scoverage
22

33
import scala.collection.mutable
4-
import scala.reflect.internal.util.SourceFile
5-
import scala.reflect.internal.util.Position
4+
import scala.reflect.internal.util.{Position, SourceFile}
65

76
/**
87
* Methods related to filtering the instrumentation and coverage.

src/main/scala/scoverage/IOUtils.scala renamed to scalac-scoverage-plugin/src/main/scala/scoverage/IOUtils.scala

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package scoverage
22

33
import java.io._
4-
import scala.xml.{XML, Utility, Node}
5-
import scala.collection.Set
6-
import scala.collection.mutable
4+
5+
import scala.collection.{Set, mutable}
76
import scala.io.Source
7+
import scala.xml.{Node, Utility, XML}
88

99
/** @author Stephen Samuel */
1010
object IOUtils {
@@ -87,19 +87,22 @@ object IOUtils {
8787
{stmt.source}
8888
</source>
8989
<package>
90-
{stmt.location._package}
90+
{stmt.location.packageName}
9191
</package>
9292
<class>
93-
{stmt.location._class}
93+
{stmt.location.className}
9494
</class>
9595
<classType>
9696
{stmt.location.classType.toString}
9797
</classType>
98+
<topLevelClass>
99+
{stmt.location.topLevelClass}
100+
</topLevelClass>
98101
<method>
99102
{stmt.location.method}
100103
</method>
101104
<path>
102-
{stmt.location.path}
105+
{stmt.location.sourcePath}
103106
</path>
104107
<id>
105108
{stmt.id.toString}
@@ -143,6 +146,7 @@ object IOUtils {
143146
val branch = (node \ "branch").text.toBoolean
144147
val _package = (node \ "package").text
145148
val _class = (node \ "class").text
149+
val topLevelClass = (node \ "topLevelClass").text
146150
val method = (node \ "method").text
147151
val path = (node \ "path").text
148152
val treeName = (node \ "treeName").text
@@ -157,8 +161,8 @@ object IOUtils {
157161
case "Object" => ClassType.Object
158162
case _ => ClassType.Class
159163
}
160-
MeasuredStatement(source,
161-
Location(_package, _class, classType, method, path),
164+
Statement(source,
165+
Location(_package, _class, topLevelClass, classType, method, path),
162166
id,
163167
start,
164168
end,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package scoverage
2+
3+
import scala.tools.nsc.Global
4+
5+
case class Location(packageName: String,
6+
className: String,
7+
topLevelClass: String,
8+
classType: ClassType,
9+
method: String,
10+
sourcePath: String) extends java.io.Serializable {
11+
val fqn = (packageName + ".").replace("<empty>.", "") + className
12+
}
13+
14+
object Location {
15+
16+
def apply(global: Global): global.Tree => Option[Location] = { tree =>
17+
18+
def packageName(s: global.Symbol): String = {
19+
s.enclosingPackage.fullName
20+
}
21+
22+
def className(s: global.Symbol): String = {
23+
// anon functions are enclosed in proper classes.
24+
if (s.enclClass.isAnonymousFunction || s.enclClass.isAnonymousClass) className(s.owner)
25+
else s.enclClass.nameString
26+
}
27+
28+
def classType(s: global.Symbol): ClassType = {
29+
if (s.enclClass.isTrait) ClassType.Trait
30+
else if (s.enclClass.isModuleOrModuleClass) ClassType.Object
31+
else ClassType.Class
32+
}
33+
34+
def topLevelClass(s: global.Symbol): String = {
35+
s.enclosingTopLevelClass.nameString
36+
}
37+
38+
def enclosingMethod(s: global.Symbol): String = {
39+
// check if we are in a proper method and return that, otherwise traverse up
40+
if (s.enclClass.isAnonymousFunction ) enclosingMethod(s.owner)
41+
else if (s.enclMethod.isPrimaryConstructor) "<init>"
42+
else Option(s.enclMethod.nameString).getOrElse("<none>")
43+
}
44+
45+
def sourcePath(symbol: global.Symbol): String = {
46+
Option(symbol.sourceFile).map(_.canonicalPath).getOrElse("<none>")
47+
}
48+
49+
Option(tree.symbol) map {
50+
symbol =>
51+
Location(
52+
packageName(symbol),
53+
className(symbol),
54+
topLevelClass(symbol),
55+
classType(symbol),
56+
enclosingMethod(symbol),
57+
sourcePath(symbol))
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)