diff options
author | ChavXO <mchavinda@colgate.edu> | 2016-05-22 14:50:37 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-08-28 23:38:57 -0400 |
commit | 51be413e5ed81cad683ef209660af36234d2c83d (patch) | |
tree | 301bc5875c1aa7e84646575c06b982fd3654deee | |
parent | c35fd1fd51c44cbb954084d0e048b3613c7cdd45 (diff) | |
download | cbt-51be413e5ed81cad683ef209660af36234d2c83d.tar.gz cbt-51be413e5ed81cad683ef209660af36234d2c83d.tar.bz2 cbt-51be413e5ed81cad683ef209660af36234d2c83d.zip |
Support for private git repositories.
-rw-r--r-- | stage2/GitDependency.scala | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala index 6510ede..6519012 100644 --- a/stage2/GitDependency.scala +++ b/stage2/GitDependency.scala @@ -2,6 +2,7 @@ package cbt import java.io._ import java.net._ import org.eclipse.jgit.api._ +import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider import org.eclipse.jgit.lib.Ref object GitDependency{ @@ -16,20 +17,34 @@ case class GitDependency( // 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 + case class GitCredentials( + username: String, + password: String + ) private object checkoutCache extends Cache[File] def checkout: File = checkoutCache{ + def authenticate(creds: Option[GitCredentials], git: CloneCommand): CloneCommand = creds match { + case Some(credentials) => git.setCredentialsProvider(new UsernamePasswordCredentialsProvider(credentials.username, credentials.password)) + case None => git + } 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) + val credentials = { + try { + val credentials = scala.io.Source.fromFile(context.projectDirectory + "/git.login").mkString.split("\n") + Some(GitCredentials(credentials(0), credentials(1))) + } catch { + case e: FileNotFoundException => None + } + } + val git = authenticate(credentials, Git.cloneRepository().setURI(url)) .setDirectory(checkoutDirectory) .call() - + logger.git(s"Checking out ref $ref") git.checkout() .setName(ref) |