--- a/README.txt Mon Aug 29 13:11:43 2011 -0400
+++ b/README.txt Mon Aug 29 14:55:54 2011 -0400
@@ -19,6 +19,9 @@
How to start geeking
--------------------
+BE PATIENT: the first time, some operations take some time because it downloads
+ all the dependencies...
+
* to launch sbt
$ ./sbt
@@ -39,12 +42,15 @@
> run 8080
-* to package the application as a standalone jar (ends up under target/ directory)
-
-> assembly
-
* to generate the eclipse configuration
> eclipse same-targets
-Have fun!
+* to package the application as a stand-alone jar (creates target/read-write-web.jar)
+
+> assembly
+
+Using the stand-alone jar
+-------------------------
+
+java -jar target/read-write-web.jar 8080 ~/WWW/2011/09 /2011/09
--- a/project/build.scala Mon Aug 29 13:11:43 2011 -0400
+++ b/project/build.scala Mon Aug 29 14:55:54 2011 -0400
@@ -45,6 +45,7 @@
import Resolvers._
import BuildSettings._
import ProguardPlugin._
+ import sbtassembly.Plugin._
def keepUnder(pakage:String):String = "-keep class %s.**" format pakage
@@ -59,7 +60,7 @@
proguardOptions += "-keep class com.hp.hpl.jena.rdf.model.impl.ModelCom"
)
- val yourProjectSettings =
+ val projectSettings =
Seq(
resolvers += ScalaToolsReleases,
resolvers += ScalaToolsSnapshots,
@@ -72,13 +73,14 @@
libraryDependencies += jena,
libraryDependencies += arq,
libraryDependencies += antiXML,
- libraryDependencies += grizzled
+ libraryDependencies += grizzled,
+ jarName in Assembly := "read-write-web.jar"
)
- lazy val yourProject = Project(
+ lazy val project = Project(
id = "read-write-web",
base = file("."),
- settings = buildSettings ++ yourProjectSettings ++ sbtassembly.Plugin.assemblySettings ++ proguardSettings
+ settings = buildSettings ++ assemblySettings ++ proguardSettings ++ projectSettings
)
--- a/src/main/scala/Main.scala Mon Aug 29 13:11:43 2011 -0400
+++ b/src/main/scala/Main.scala Mon Aug 29 14:55:54 2011 -0400
@@ -21,7 +21,7 @@
import org.w3.readwriteweb.util._
-class ReadWriteWeb(implicit rm:ResourceManager) {
+class ReadWriteWeb(rm:ResourceManager) {
val logger:Logger = LoggerFactory.getLogger(this.getClass)
@@ -95,18 +95,27 @@
// regular Java main
def main(args: Array[String]) {
- val (port, directory) = args.toList match {
- case port :: directory :: Nil => (port.toInt, directory)
- case _ => sys.error("wrong arguments")
+ val (port, baseDirectory, baseURL) = args.toList match {
+ case port :: directory :: base :: Nil => (port.toInt, new File(directory), base)
+ case _ => {
+ println("example usage:\n\tjava -jar read-write-web.jar 8080 ~/WWW/2011/09 /2011/09")
+ System.exit(1)
+ null
+ }
}
- implicit val filesystem = new Filesystem(new File(directory), "/")
+ if (! baseDirectory.exists) {
+ println("%s does not exist" format (baseDirectory.getAbsolutePath))
+ System.exit(2)
+ }
+
+ val filesystem = new Filesystem(baseDirectory, baseURL)
- val app = new ReadWriteWeb
+ val app = new ReadWriteWeb(filesystem)
// configures and launches a Jetty server
unfiltered.jetty.Http(port).filter {
- // a jee Servlet filter that logs request
+ // a jee Servlet filter that logs HTTP requests
new Filter {
def destroy():Unit = ()
def doFilter(request:ServletRequest, response:ServletResponse, chain:FilterChain):Unit = {
--- a/src/main/scala/Resource.scala Mon Aug 29 13:11:43 2011 -0400
+++ b/src/main/scala/Resource.scala Mon Aug 29 14:55:54 2011 -0400
@@ -26,7 +26,7 @@
def sanityCheck():Boolean = baseDirectory.exists
def resource(url:URL):Resource = new Resource {
- val relativePath:String = url.getPath.replaceAll("^"+basePath.toString, "")
+ val relativePath:String = url.getPath.replaceAll("^"+basePath.toString+"/?", "")
val fileOnDisk = new File(baseDirectory, relativePath)
private def createFileOnDisk():Unit = {
--- a/src/test/scala/Test.scala Mon Aug 29 13:11:43 2011 -0400
+++ b/src/test/scala/Test.scala Mon Aug 29 14:55:54 2011 -0400
@@ -22,7 +22,7 @@
val base = new File(new File(System.getProperty("java.io.tmpdir")), "readwriteweb")
val joe = host / "2007/wiki/people/JoeLambda"
val baseURI = "%s%s" format (joe.host, joe.path)
- val joeOnDisk = new File(base, "2007/wiki/people/JoeLambda")
+ val joeOnDisk = new File(base, "people/JoeLambda")
doBeforeSpec {
base.deleteRecursively()
@@ -33,9 +33,9 @@
// if (joeOnDisk.exists) joeOnDisk.delete()
}
- implicit val filesystem = new Filesystem(base, "/")
+ val filesystem = new Filesystem(base, "/2007/wiki")
- def setup = { _.filter(new ReadWriteWeb()(filesystem).read) }
+ def setup = { _.filter(new ReadWriteWeb(filesystem).read) }
val joeRDF =
"""
@@ -49,9 +49,6 @@
val initialModel = modelFromString(joeRDF, baseURI)
-// <foaf:openid rdf:resource="/2007/wiki/people/JoeLambda" />
-// <foaf:img rdf:resource="/2007/wiki/people/JoeLambda/images/me.jpg" />
-
"PUTing an RDF document on Joe's URI (which does not exist yet)" should {
"return a 201" in {
val httpCode:Int = Http(joe.put(joeRDF) get_statusCode)