Support for readonly file ProjectRef

This allows using a project reference that points to a readonly
directory.

The use case for this is having sbt plugin projects on a network
share (readonly) that you can just point to. The plugin projects
get copied and built automatically, just like a git project
reference gets cloned and built.

This will ease plugin imcompatibilies between minor sbt versions,
avoiding to have to cross build plugins against all compatible sbt
versions.
This commit is contained in:
Fred Dubois 2011-07-23 12:58:24 -04:00
parent 4ae0ba6b57
commit 4ffe240eca
1 changed files with 20 additions and 1 deletions

View File

@ -46,10 +46,29 @@ object RetrieveUnit
case "http" | "https" => Some { () => downloadAndExtract(base, tmp); tmp }
case "file" =>
val f = new File(base)
if(f.isDirectory) Some(() => f) else None
if(f.isDirectory)
{
val finalDir = if (!f.canWrite) retrieveRODir(f, tmp) else f
Some(() => finalDir)
}
else None
case _ => None
}
}
def retrieveRODir(base: File, tempDir: File): File =
{
if (!tempDir.exists)
{
try {
IO.copyDirectory(base, tempDir)
} catch {
case e =>
IO.delete(tempDir)
throw e
}
}
tempDir
}
def downloadAndExtract(base: URI, tempDir: File): Unit = if(!tempDir.exists) IO.unzipURL(base.toURL, tempDir)
def temporary(tempDir: File, uri: URI): File = new File(tempDir, Hash.halve(hash(uri)))
def hash(uri: URI): String = Hash.toHex(Hash(uri.toASCIIString))