Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/Application.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package controllers

import _root_.util.Config
import play.api._
import play.api.mvc._
import service.engine.{ScalaProjectParser, CoberturaXMLParser, CheckstyleXMLParser}
Expand All @@ -26,7 +27,7 @@ object Application extends Controller {
val coberturaReport = CoberturaXMLParser.produceCodeCoverageReport(loadFile("public/resources/coverage-report/cobertura.xml"))
val checkstyleIssues = CheckstyleXMLParser.produceIssues(loadFile("public/resources/scala-radar_style.xml"))

val sourcePath = "/Users/ugobourdon/Dev/Projects/ScalaQuality/scala-radar/app"
val sourcePath = Config.getApplicationPath + "/app"
val scalaFiles: Set[Path] = (sourcePath ** "*.scala").toSet

val projectMetadatas = ScalaProjectParser.produceScalaProjectMetadatas(scalaFiles)
Expand Down
10 changes: 10 additions & 0 deletions app/util/Config.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package util

import com.typesafe.config.ConfigFactory

object Config {
val conf = ConfigFactory.load("paths.conf")
val applicationPath = Interpreter.interpretAsStringVal(conf.getString("app.path"))

def getApplicationPath() = applicationPath
}
25 changes: 25 additions & 0 deletions app/util/Interpreter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package util

import scala.tools.nsc.interpreter.IMain
import java.io.File
import scala.tools.nsc.Settings

object Interpreter {

def interpretAsStringVal(codeToInterpret: String) = {
val settings = new Settings

//Including scala-library in project is necessary in order to give to play framework this lib, play (through sbt) doesn't include scala-library in classpath
settings.bootclasspath.value +=scala.tools.util.PathResolver.Environment.javaBootClassPath + File.pathSeparator + "lib/scala-library-2.10.3.jar"
val interpreter = new IMain(settings){
override protected def parentClassLoader = settings.getClass.getClassLoader()
}

interpreter.interpret("val resultVal=" + codeToInterpret)

val resultVal = interpreter.valueOfTerm("resultVal").get.toString
interpreter.close()
resultVal
}

}
1 change: 1 addition & 0 deletions conf/paths.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app.path="new java.io.File(\".\").getAbsolutePath()"
Binary file added lib/scala-library-2.10.3.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion project/ScalaRadarBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ object ScalaRadarBuild extends Build {
"joda-time" % "joda-time" % "2.3",
"org.scalatest" %% "scalatest" % "2.0" % "test",
"com.typesafe.akka" %% "akka-testkit" % "2.2.1" % "test",
"org.mockito" % "mockito-all" % "1.9.5" % "test"
"org.mockito" % "mockito-all" % "1.9.5" % "test",
"org.scala-lang" % "scala-compiler" % "2.10.3"
)

val main = play.Project(appName, appVersion, appDependencies).settings(
Expand Down
4 changes: 3 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ logLevel := Level.Warn
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")

addSbtPlugin("com.sqality.scct" % "sbt-scct" % "0.3")
3 changes: 2 additions & 1 deletion test/service/engine/ScalaProjectParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service.engine
import org.scalatest.{Matchers, FunSuite}
import model.{ScalaMetadatas, ScalaFileMetadatas, ScalaProjectMetaDatas}
import scalax.file.ImplicitConversions._
import util.Config

class ScalaProjectParserTest extends FunSuite with Matchers {

Expand All @@ -13,7 +14,7 @@ class ScalaProjectParserTest extends FunSuite with Matchers {
import scalax.file.PathSet

// find all .scala files in a sourcePath or one of its sub-directories
val sourcePath = "/Users/ugobourdon/Dev/Projects/ScalaQuality/scala-radar/app"
val sourcePath = Config.getApplicationPath() + "/app"
val scalaFiles: PathSet[Path] = sourcePath ** "*.scala"
//scalaFiles.toSet.foreach(println)
}
Expand Down
11 changes: 11 additions & 0 deletions test/util/ConfigTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package util

import org.scalatest.{Matchers, FunSuite}

class ConfigTest extends FunSuite with Matchers {

test("should retrieve application path from project config") {
Config.getApplicationPath() should include ("scala-radar")
}

}
11 changes: 11 additions & 0 deletions test/util/InterpreterTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package util

import org.scalatest.{Matchers, FunSuite}

class InterpreterTest extends FunSuite with Matchers {

test("should interpret scala val on the fly") {
val applicationPath = Interpreter.interpretAsStringVal("new java.io.File(\".\").getAbsolutePath()")
applicationPath should include ("scala-radar")
}
}