diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-12 13:37:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-12 13:37:35 -0400 |
commit | 796a9f55e9400fb517ab918ad980a6eeeae58b85 (patch) | |
tree | 8408b2fadedb5093be4c349f7a187da581e62b01 | |
parent | 918d158f0ce87c664555d0d624fb3664c7015851 (diff) | |
parent | 5050e95c5db30a49f1817e5a85de197ad2efc689 (diff) | |
download | cbt-796a9f55e9400fb517ab918ad980a6eeeae58b85.tar.gz cbt-796a9f55e9400fb517ab918ad980a6eeeae58b85.tar.bz2 cbt-796a9f55e9400fb517ab918ad980a6eeeae58b85.zip |
Merge pull request #422 from cvogt/git-sources
expose git checkout functionality for embedding sources from git
-rw-r--r-- | ports/migration-manager/build/build.scala | 12 | ||||
-rw-r--r-- | stage2/GitDependency.scala | 93 |
2 files changed, 58 insertions, 47 deletions
diff --git a/ports/migration-manager/build/build.scala b/ports/migration-manager/build/build.scala new file mode 100644 index 0000000..43b24f5 --- /dev/null +++ b/ports/migration-manager/build/build.scala @@ -0,0 +1,12 @@ +package migration_manager_build +import cbt._ +class Build(val context: Context) extends BaseBuild{ + override def dependencies = + Resolver( mavenCentral ).bind( + MavenDependency( "org.scala-lang", "scala-compiler", "2.11.8" ) + ) + def mima = GitDependency.checkout( + "git@github.com:typesafehub/migration-manager.git", "92cbce52b4bf04ca1c338f34818ebfb9f0ebc285" + ) + override def generatedSources = Seq( mima / "core" ) +} diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala index 028401b..f6812e4 100644 --- a/stage2/GitDependency.scala +++ b/stage2/GitDependency.scala @@ -8,14 +8,32 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider import org.eclipse.jgit.lib.Ref object GitDependency{ - val GitUrl = "(git:|https:|file:/)//([^/]+)/(.+)".r + val GitUrl = "(git@|git://|https://|file:///)([^/:]+)[/:](.+)".r 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 = { + def moduleKey = ( + this.getClass.getName + ++ "(" ++ url ++ subDirectory.map("/" ++ _).getOrElse("") ++ "#" ++ ref + ++ ", " + ++ pathToNestedBuild.mkString(", ") + ++ ")" + ) + + val taskCache = new PerClassCache(context.transientCache, moduleKey)(context.logger) + + val c = taskCache[Dependency]("checkout").memoize{ checkout( url, ref ) } + DirectoryDependency( + context.copy( + workingDirectory = subDirectory.map(c / _).getOrElse(c) + ), + pathToNestedBuild: _* + ) + } + def checkout(url: String, ref: String)(implicit context: Context): File = { // 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){ @@ -30,52 +48,33 @@ object GitDependency{ } val logger = context.logger - - def moduleKey = ( - this.getClass.getName - ++ "(" ++ url ++ subDirectory.map("/" ++ _).getOrElse("") ++ "#" ++ ref - ++ ", " - ++ pathToNestedBuild.mkString(", ") - ++ ")" - ) - - val taskCache = new PerClassCache(context.transientCache, moduleKey)(logger) - - 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 GitUrl( _, domain, path ) = url + val checkoutDirectory = context.cache / s"git/$domain/${path.stripSuffix(".git")}/$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 - assert( actualRef == ref, s"actual ref '$actualRef' does not match expected ref '$ref'") - checkoutDirectory - } + 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() - DirectoryDependency( - context.copy( - workingDirectory = checkout ++ subDirectory.map("/" ++ _).getOrElse("") - ), - pathToNestedBuild: _* - ) + 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 } } |