blob: 0457c3c5d7e89880e212533742dfbc5f5e307baf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package cbt
import java.io._
import java.net._
import scala.collection.immutable.Seq
import org.eclipse.jgit.api._
import org.eclipse.jgit.lib.Ref
object GitDependency{
val GitUrl = "(git:|https:|file:/)//([^/]+)/(.+)".r
}
case class GitDependency(
url: String, ref: String, subDirectory: Option[String] = None // example: git://github.com/cvogt/cbt.git#<some-hash>
)(implicit val logger: Logger, classLoaderCache: ClassLoaderCache, context: Context ) extends DependencyImplementation{
import GitDependency._
override def lib = new Lib(logger)
// TODO: add support for authentication via ssh and/or https
// See http://www.codeaffine.com/2014/12/09/jgit-authentication/
private val GitUrl( _, domain, path ) = url
private object checkoutCache extends Cache[File]
def checkout: File = checkoutCache{
val checkoutDirectory = context.cache ++ s"/git/$domain/$path/$ref"
if(checkoutDirectory.exists){
logger.git(s"Found existing checkout of $url#$ref in $checkoutDirectory")
} else {
logger.git(s"Cloning $url into $checkoutDirectory")
val git =
Git.cloneRepository()
.setURI(url)
.setDirectory(checkoutDirectory)
.call()
logger.git(s"Checking out ref $ref")
git.checkout()
.setName(ref)
.call()
}
checkoutDirectory
}
private object dependencyCache extends Cache[DependencyImplementation]
def dependency = dependencyCache{
BuildDependency(
context.copy(
projectDirectory = checkout ++ subDirectory.map("/" ++ _).getOrElse("")
)
)
}
def dependencies = Seq(dependency)
def exportedClasspath = ClassPath(Seq())
private[cbt] def targetClasspath = exportedClasspath
def needsUpdate: Boolean = false
}
|