aboutsummaryrefslogtreecommitdiff
path: root/stage2/GitDependency.scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-11 16:41:00 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-11 16:41:00 -0500
commit0fcc91ebcd289784811a10c5bc901af644d5fc12 (patch)
treec58ec83445d71be95aac944d78da322891e5c2a6 /stage2/GitDependency.scala
parentc7a5c5d7e23355ea14e8c095f750b47f308c032f (diff)
downloadcbt-0fcc91ebcd289784811a10c5bc901af644d5fc12.tar.gz
cbt-0fcc91ebcd289784811a10c5bc901af644d5fc12.tar.bz2
cbt-0fcc91ebcd289784811a10c5bc901af644d5fc12.zip
Make GitDependency and DirectoryDependency simply return Build objects
Diffstat (limited to 'stage2/GitDependency.scala')
-rw-r--r--stage2/GitDependency.scala122
1 files changed, 57 insertions, 65 deletions
diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala
index f2ac7a6..028401b 100644
--- a/stage2/GitDependency.scala
+++ b/stage2/GitDependency.scala
@@ -9,70 +9,68 @@ 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>
- pathToNestedBuild: Seq[String] = Seq()
-)(implicit val logger: Logger, classLoaderCache: ClassLoaderCache, context: Context ) extends DependencyImplementation{
- import GitDependency._
- override def lib = new Lib(logger)
- def classLoaderCache = context.classLoaderCache
- def moduleKey = (
- this.getClass.getName
- ++ "(" ++ url ++ subDirectory.map("/" ++ _).getOrElse("") ++ "#" ++ ref
- ++ ", "
- ++ pathToNestedBuild.mkString(", ")
- ++ ")"
- )
- def transientCache = context.transientCache
- // 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
+ def apply(
+ url: String, ref: String, subDirectory: Option[String] = None, // example: git://github.com/cvogt/cbt.git#<some-hash>
+ pathToNestedBuild: Seq[String] = Seq()
+ )(implicit context: Context ): BuildInterface = {
+ // TODO: add support for authentication via ssh and/or https
+ // See http://www.codeaffine.com/2014/12/09/jgit-authentication/
+ val GitUrl( _, domain, path ) = url
+ val credentialsFile = context.workingDirectory ++ "/git.login"
+ def authenticate(_git: CloneCommand) =
+ if(!credentialsFile.exists){
+ _git
+ } else {
+ val (user, password) = {
+ // TODO: implement safer method than reading credentials from plain text file
+ val c = new String(readAllBytes(credentialsFile.toPath)).split("\n").head.trim.split(":")
+ (c(0), c.drop(1).mkString(":"))
+ }
+ _git.setCredentialsProvider( new UsernamePasswordCredentialsProvider(user, password) )
+ }
- private val credentialsFile = context.workingDirectory ++ "/git.login"
+ val logger = context.logger
- private def authenticate(_git: CloneCommand) =
- if(!credentialsFile.exists){
- _git
- } else {
- val (user, password) = {
- // TODO: implement safer method than reading credentials from plain text file
- val c = new String(readAllBytes(credentialsFile.toPath)).split("\n").head.trim.split(":")
- (c(0), c.drop(1).mkString(":"))
- }
- _git.setCredentialsProvider( new UsernamePasswordCredentialsProvider(user, password) )
- }
+ def moduleKey = (
+ this.getClass.getName
+ ++ "(" ++ url ++ subDirectory.map("/" ++ _).getOrElse("") ++ "#" ++ ref
+ ++ ", "
+ ++ pathToNestedBuild.mkString(", ")
+ ++ ")"
+ )
- def checkout: File = taskCache[GitDependency]("checkout").memoize{
- val checkoutDirectory = context.cache ++ s"/git/$domain/$path/$ref"
- val _git = if(checkoutDirectory.exists){
- logger.git(s"Found existing checkout of $url#$ref in $checkoutDirectory")
- val _git = new Git(new FileRepository(checkoutDirectory ++ "/.git"))
- val actualRef = _git.getRepository.getBranch
- if(actualRef != ref){
- logger.git(s"actual ref '$actualRef' does not match expected ref '$ref' - fetching and checking out")
- _git.fetch().call()
- _git.checkout().setName(ref).call
- }
- _git
- } else {
- logger.git(s"Cloning $url into $checkoutDirectory")
- val _git = authenticate(
- Git
- .cloneRepository()
- .setURI(url)
- .setDirectory(checkoutDirectory)
- ).call()
+ val taskCache = new PerClassCache(context.transientCache, moduleKey)(logger)
- logger.git(s"Checking out ref $ref")
- _git.checkout().setName(ref).call()
- _git
+ def checkout: File = taskCache[Dependency]("checkout").memoize{
+ val checkoutDirectory = context.cache ++ s"/git/$domain/$path/$ref"
+ val _git = if(checkoutDirectory.exists){
+ logger.git(s"Found existing checkout of $url#$ref in $checkoutDirectory")
+ val _git = new Git(new FileRepository(checkoutDirectory ++ "/.git"))
+ val actualRef = _git.getRepository.getBranch
+ if(actualRef != ref){
+ logger.git(s"actual ref '$actualRef' does not match expected ref '$ref' - fetching and checking out")
+ _git.fetch().call()
+ _git.checkout().setName(ref).call
+ }
+ _git
+ } else {
+ logger.git(s"Cloning $url into $checkoutDirectory")
+ val _git = authenticate(
+ Git
+ .cloneRepository()
+ .setURI(url)
+ .setDirectory(checkoutDirectory)
+ ).call()
+
+ logger.git(s"Checking out ref $ref")
+ _git.checkout().setName(ref).call()
+ _git
+ }
+ val actualRef = _git.getRepository.getBranch
+ assert( actualRef == ref, s"actual ref '$actualRef' does not match expected ref '$ref'")
+ checkoutDirectory
}
- val actualRef = _git.getRepository.getBranch
- assert( actualRef == ref, s"actual ref '$actualRef' does not match expected ref '$ref'")
- checkoutDirectory
- }
- def dependency = taskCache[GitDependency]("dependency").memoize{
+
DirectoryDependency(
context.copy(
workingDirectory = checkout ++ subDirectory.map("/" ++ _).getOrElse("")
@@ -80,10 +78,4 @@ case class GitDependency(
pathToNestedBuild: _*
)
}
-
- def dependencies = Seq(dependency)
-
- def exportedClasspath = ClassPath()
- private[cbt] def targetClasspath = exportedClasspath
- def lastModified: Long = dependency.lastModified
}