diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-18 00:05:54 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-18 00:05:54 -0400 |
commit | cb37198374fa25e2ac1f46ccd6fe3ba98d79dd24 (patch) | |
tree | db2715a94ba7afe8876a29f4d14078f7b8bea3a1 /stage2 | |
parent | f9ce0472aea0d6f646e8f7487f63ab8c4e42d22a (diff) | |
download | cbt-cb37198374fa25e2ac1f46ccd6fe3ba98d79dd24.tar.gz cbt-cb37198374fa25e2ac1f46ccd6fe3ba98d79dd24.tar.bz2 cbt-cb37198374fa25e2ac1f46ccd6fe3ba98d79dd24.zip |
Add support for git dependencies
pair coded with @chavxo
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/GitDependency.scala | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala new file mode 100644 index 0000000..c3e38b6 --- /dev/null +++ b/stage2/GitDependency.scala @@ -0,0 +1,49 @@ +package cbt +import java.io._ +import java.net._ +import scala.collection.immutable.Seq +import org.eclipse.jgit.api._ +import org.eclipse.jgit.lib.Ref + +case class GitDependency( + url: String, ref: String // example: git://github.com/cvogt/cbt.git#<some-hash> +)(implicit val logger: Logger) extends Dependency{ + 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 = "(git|https)://([^/]+)/(.+)".r + private val GitUrl( _, domain, path ) = url + + private object dependenciesCache extends Cache[Seq[Dependency]] + def dependencies = dependenciesCache{ + val checkoutDirectory = paths.cbtHome ++ s"/cache/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() + + } + val managedBuild = lib.loadDynamic( + Context( cwd = checkoutDirectory, args = Seq(), logger ) + ) + Seq( managedBuild ) + } + + def exportedClasspath = ClassPath(Seq()) + def exportedJars = Seq() + private[cbt] def targetClasspath = exportedClasspath + def updated: Boolean = false +} |