--- a/.hgignore Sat Jun 12 20:02:19 2010 -0400
+++ b/.hgignore Sun Jun 13 18:35:41 2010 -0400
@@ -10,4 +10,5 @@
*.class
*.log
\#*
-.\#*
\ No newline at end of file
+.\#*
+src/main/resources
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project/build/BSBMPlugin.scala Sun Jun 13 18:35:41 2010 -0400
@@ -0,0 +1,86 @@
+import sbt._
+import java.io.File
+import java.net.URL
+import Process._
+
+/**
+ * BSBMPlugin introduces two tasks in sbt
+ * - bsbm -> downloads, unpackages the Berlin SPARQL Benchmark and generates
+ * a default set of sql file
+ * - bsbm-load -> execute one, several or all the generated sql scripts
+ * this taks enables autocompletion for its valid arguments
+ * Requirements: src/main/resources/database.properties must be filled
+ * with correct values to access the database
+ */
+trait BSBMPlugin extends Project { self =>
+
+ val unzipTo = path("target")
+ val bsbmtools = unzipTo / "bsbmtools"
+ val dataset = bsbmtools / "dataset"
+
+ /**
+ * download and unpackage bsbmtool
+ */
+ def downloadbsbm() = {
+ val zip = path("target") / "bsbmtools.zip" asFile
+
+ if (! zip.exists) {
+ val bsbmUrl = "http://downloads.sourceforge.net/project/bsbmtools/bsbmtools/bsbmtools-0.1/bsbmtools.zip"
+ new URL(bsbmUrl) #> zip ! log
+ FileUtilities.unzip(zip, unzipTo, log)
+ }
+ }
+
+ /**
+ * defines a task that downloads the BSBM tools and then
+ * creates the sql scripts with some default arguments
+ */
+ lazy val bsbm = task {
+
+ downloadbsbm()
+
+ FileUtilities.clean(dataset, log)
+ FileUtilities.clean(bsbmtools / "td_data", log)
+ ( (new java.lang.ProcessBuilder("java", "-cp", "bin:lib/ssj.jar", "benchmark.generator.Generator", "-fc", "-pc", "1000", "-s", "sql")) directory (bsbmtools asFile) ) ! log
+
+ None
+ }
+
+ /**
+ * list all the generated sql scripts
+ */
+ def sqlFiles:List[String] = (dataset * "*.sql").getFiles.map{ _.getName }.toList.sort{ _ < _ }
+
+ /* see http://code.google.com/p/simple-build-tool/wiki/Properties
+ * this is where we add a dependency to another property file
+ */
+ lazy val extra = new BasicEnvironment {
+ def log = self.log
+ def envBackingPath = "src" / "main" / "resources" / "database.properties"
+ lazy val host = property[String]
+ lazy val user = property[String]
+ lazy val password = property[String]
+ }
+
+ /**
+ * execute a mysql client command against a filename, which actually
+ * is a sql script
+ */
+ def load(filename:String) = {
+ log.info("loading "+filename)
+ val host = extra.host.value
+ val user = extra.user.value
+ val password = extra.password.value
+ ( (new java.lang.ProcessBuilder("mysql", "--host="+host, "--user="+user, "--password="+password, "-e", "source "+filename)) directory (dataset asFile) ) ! log
+ }
+
+ /**
+ * defines a task bsbm-load
+ */
+ lazy val bsbmLoad = task { args =>
+ val files:List[String] = if (args.length == 0) sqlFiles else args.toList
+ files foreach { file => load(file)}
+ task { None }
+ } completeWith sqlFiles
+
+}
--- a/project/build/RDB2RDF.scala Sat Jun 12 20:02:19 2010 -0400
+++ b/project/build/RDB2RDF.scala Sun Jun 13 18:35:41 2010 -0400
@@ -1,9 +1,6 @@
import sbt._
-import java.io.File
-import java.net.URL
-import Process._
-class RDB2RDF(info: ProjectInfo) extends DefaultWebProject(info) {
+class RDB2RDF(info: ProjectInfo) extends DefaultWebProject(info) with BSBMPlugin {
override def compileOptions = super.compileOptions ++ Seq(Unchecked, Deprecation, ExplainTypes)
@@ -16,26 +13,8 @@
val mysql = "mysql" % "mysql-connector-java" % "5.1.12"
- val unzipTo = path("target")
- val bsbmtools = unzipTo / "bsbmtools"
-
- // define the bsbm task wich download and set up the database
-
- lazy val bsbm = task {
- val zip = path("target") / "bsbmtools.zip" asFile
+ override def defaultExcludes = super.defaultExcludes || "*~"
- if (! zip.exists) {
- val bsbmUrl = "http://downloads.sourceforge.net/project/bsbmtools/bsbmtools/bsbmtools-0.1/bsbmtools.zip"
- new URL(bsbmUrl) #> zip ! log
- FileUtilities.unzip(zip, unzipTo, log)
- }
-
- FileUtilities.clean(bsbmtools / "dataset", log)
- FileUtilities.clean(bsbmtools / "td_data", log)
- ( (new java.lang.ProcessBuilder("java", "-cp", "bin:lib/ssj.jar", "benchmark.generator.Generator", "-fc", "-pc", "1000", "-s", "sql")) directory (bsbmtools asFile) ) ! log
-
- None
- }
+ override def webappUnmanaged = super.webappUnmanaged +++ ("src" / "main" / "resources" / "database.properties")
}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/resources/database.properties Sun Jun 13 18:35:41 2010 -0400
@@ -0,0 +1,4 @@
+# this file in unmanaged
+host = localhost
+user = root
+password =