diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-03 00:09:19 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-03 00:09:26 -0400 |
commit | 83d6e39764103bde44d5812aa873ed7537cc8c97 (patch) | |
tree | 60a070ef1511aa525cec9bf4c19034804b829679 /stage2 | |
parent | 8eae49b7b0a39f23518680b56429314db3d977e1 (diff) | |
download | cbt-83d6e39764103bde44d5812aa873ed7537cc8c97.tar.gz cbt-83d6e39764103bde44d5812aa873ed7537cc8c97.tar.bz2 cbt-83d6e39764103bde44d5812aa873ed7537cc8c97.zip |
Implement alternative resolvers
This commit also
- requires Dependencies to explicitly implement canBeCached
- unifies some logic for dependency downloading
- moves SBT-like dependency DSL into its own trait
- error message showing build directory for exceptions in builds
Not splitting this up in favor of faster progress to 1.0.
The user facing API can probably be slightly improved using implicits
inside of BasicBuild, but we can do that later.
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/AdminTasks.scala | 42 | ||||
-rw-r--r-- | stage2/BasicBuild.scala | 27 | ||||
-rw-r--r-- | stage2/BuildBuild.scala | 5 | ||||
-rw-r--r-- | stage2/BuildDependency.scala | 1 | ||||
-rw-r--r-- | stage2/GitDependency.scala | 1 | ||||
-rw-r--r-- | stage2/SbtDependencyDsl.scala | 43 | ||||
-rw-r--r-- | stage2/mixins.scala | 4 |
7 files changed, 72 insertions, 51 deletions
diff --git a/stage2/AdminTasks.scala b/stage2/AdminTasks.scala index a18c16a..655b2b0 100644 --- a/stage2/AdminTasks.scala +++ b/stage2/AdminTasks.scala @@ -9,7 +9,7 @@ class AdminTasks(lib: Lib, args: Seq[String], cwd: File){ args(1).split(",").toVector.map{ d => val v = d.split(":") - new JavaDependency(v(0),v(1),v(2)).classpath + MavenRepository.central.resolveOne(MavenDependency(v(0),v(1),v(2))).classpath } ) } @@ -17,15 +17,17 @@ class AdminTasks(lib: Lib, args: Seq[String], cwd: File){ args(1).split(",").toVector.map{ d => val v = d.split(":") - new JavaDependency(v(0),v(1),v(2)).dependencyTree + MavenRepository.central.resolveOne(MavenDependency(v(0),v(1),v(2))).dependencyTree }.mkString("\n\n") } def amm = ammonite def ammonite = { val version = args.lift(1).getOrElse(constants.scalaVersion) val scalac = new ScalaCompilerDependency( version ) - val d = JavaDependency( - "com.lihaoyi","ammonite-repl_2.11.7",args.lift(1).getOrElse("0.5.7") + val d = MavenRepository.central.resolveOne( + MavenDependency( + "com.lihaoyi","ammonite-repl_2.11.7",args.lift(1).getOrElse("0.5.7") + ) ) // FIXME: this does not work quite yet, throws NoSuchFileException: /ammonite/repl/frontend/ReplBridge$.class lib.runMain( @@ -46,41 +48,25 @@ class AdminTasks(lib: Lib, args: Seq[String], cwd: File){ val scalaMajorVersion = scalaVersion.split("\\.").take(2).mkString(".") val scalaXmlVersion = args.lift(2).getOrElse(constants.scalaXmlVersion) val zincVersion = args.lift(3).getOrElse(constants.zincVersion) - /* - def tree(d: JavaDependency, indent: Int): String ={ - val dependencies = { - if( d.dependencies.nonEmpty ){ - d.dependencies.map{ - case d: JavaDependency => tree(d,indent + 1) - }.mkString(",\n" ++ ( " " * indent ),",\n" ++ ( " " * indent ), "") - } else "" - } - ( - s"""new EarlyDependency( "${d.groupId}", "${d.artifactId}", "${d.version}", "${d.jarSha1}"$dependencies)""" - ) - }*/ val scalaDeps = Seq( - JavaDependency("org.scala-lang","scala-reflect",scalaVersion), - JavaDependency("org.scala-lang","scala-compiler",scalaVersion) + MavenRepository.central.resolveOne(MavenDependency("org.scala-lang","scala-reflect",scalaVersion)), + MavenRepository.central.resolveOne(MavenDependency("org.scala-lang","scala-compiler",scalaVersion)) ) val scalaXml = Dependencies( - JavaDependency("org.scala-lang.modules","scala-xml_"+scalaMajorVersion,scalaXmlVersion), - JavaDependency("org.scala-lang","scala-library",scalaVersion) + MavenRepository.central.resolveOne(MavenDependency("org.scala-lang.modules","scala-xml_"+scalaMajorVersion,scalaXmlVersion)), + MavenRepository.central.resolveOne(MavenDependency("org.scala-lang","scala-library",scalaVersion)) ) - val zinc = JavaDependency("com.typesafe.zinc","zinc",zincVersion) - println(zinc.dependencyTree) + val zinc = MavenRepository.central.resolveOne(MavenDependency("com.typesafe.zinc","zinc",zincVersion)) - def valName(dep: JavaDependency) = { + def valName(dep: BoundMavenDependency) = { val words = dep.artifactId.split("_").head.split("-") words(0) ++ words.drop(1).map(s => s(0).toString.toUpperCase ++ s.drop(1)).mkString ++ "_" ++ dep.version.replace(".","_") ++ "_" } - def vals(d: JavaDependency) = s""" """ - - def jarVal(dep: JavaDependency) = "_" + valName(dep) +"Jar" - def transitive(dep: Dependency) = (dep +: dep.transitiveDependencies.reverse).collect{case d: JavaDependency => d} + def jarVal(dep: BoundMavenDependency) = "_" + valName(dep) +"Jar" + def transitive(dep: Dependency) = (dep +: dep.transitiveDependencies.reverse).collect{case d: BoundMavenDependency => d} def codeEach(dep: Dependency) = { transitive(dep).tails.map(_.reverse).toVector.reverse.drop(1).map{ deps => diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index eac78ea..39cc9e3 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -12,7 +12,7 @@ import scala.collection.immutable.Seq import scala.util._ class BasicBuild( context: Context ) extends Build( context ) -class Build(val context: Context) extends Dependency with TriggerLoop{ +class Build(val context: Context) extends Dependency with TriggerLoop with SbtDependencyDsl{ // library available to builds implicit final val logger: Logger = context.logger implicit final val classLoaderCache: ClassLoaderCache = context.classLoaderCache @@ -21,6 +21,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ // ========== general stuff ========== + override def canBeCached = false def enableConcurrency = false final def projectDirectory: File = lib.realpath(context.cwd) assert( projectDirectory.exists, "projectDirectory does not exist: " ++ projectDirectory.string ) @@ -33,7 +34,9 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ def zincVersion = "0.3.9" def dependencies: Seq[Dependency] = Seq( - "org.scala-lang" % "scala-library" % scalaVersion + MavenRepository.central.resolve( + "org.scala-lang" % "scala-library" % scalaVersion + ) ) // ========== paths ========== @@ -85,22 +88,6 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ scalaVersion: String = scalaMajorVersion ) = lib.ScalaDependency( groupId, artifactId, version, classifier, scalaVersion ) - /** SBT-like dependency builder DSL for syntax compatibility */ - class DependencyBuilder2( groupId: String, artifactId: String, scalaVersion: Option[String] ){ - def %(version: String) = scalaVersion.map( - v => ScalaDependency(groupId, artifactId, version, scalaVersion = v) - ).getOrElse( - JavaDependency(groupId, artifactId, version) - ) - } - implicit class DependencyBuilder(groupId: String){ - def %%(artifactId: String) = new DependencyBuilder2( groupId, artifactId, Some(scalaMajorVersion) ) - def %(artifactId: String) = new DependencyBuilder2( groupId, artifactId, None ) - } - implicit class DependencyBuilder3(d: JavaDependency){ - def %(classifier: String) = d.copy(classifier = Classifier(Some(classifier))) - } - final def BuildDependency(path: File) = cbt.BuildDependency( context.copy( cwd = path, args = Seq() ) ) @@ -129,8 +116,8 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ def needsUpdate: Boolean = needsUpdateCache( context.cbtHasChanged || lib.needsUpdate( sourceFiles, compileStatusFile ) - || transitiveDependencies.exists(_.needsUpdate) - ) + || transitiveDependencies.exists(_.needsUpdate) + ) private object compileCache extends Cache[Option[File]] def compile: Option[File] = compileCache{ diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala index 9746d8c..45d86f8 100644 --- a/stage2/BuildBuild.scala +++ b/stage2/BuildBuild.scala @@ -5,7 +5,7 @@ import scala.collection.immutable.Seq class BuildBuild(context: Context) extends Build(context){ override def dependencies = Seq( CbtDependency()(context.logger) ) ++ super.dependencies def managedBuildDirectory: File = lib.realpath( projectDirectory.parent ) - val managedBuild = { + val managedBuild = try{ val managedContext = context.copy( cwd = managedBuildDirectory ) val cl = new cbt.URLClassLoader( exportedClasspath, @@ -16,6 +16,9 @@ class BuildBuild(context: Context) extends Build(context){ .getConstructor(classOf[Context]) .newInstance(managedContext) .asInstanceOf[Build] + } catch { + case e: Exception => + throw new Exception("during build: "+context.cwd, e) } override def triggerLoopFiles = super.triggerLoopFiles ++ managedBuild.triggerLoopFiles override def finalBuild = managedBuild.finalBuild diff --git a/stage2/BuildDependency.scala b/stage2/BuildDependency.scala index e3a01c7..19357f9 100644 --- a/stage2/BuildDependency.scala +++ b/stage2/BuildDependency.scala @@ -21,6 +21,7 @@ case class BuildDependency(context: Context) extends TriggerLoop{ final override lazy val lib: Lib = new Lib(logger) private val root = lib.loadRoot( context.copy(args=Seq()) ) lazy val build = root.finalBuild + override def canBeCached = build.canBeCached def exportedClasspath = ClassPath(Seq()) def exportedJars = Seq() def dependencies = Seq(build) diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala index aeeeead..27bf253 100644 --- a/stage2/GitDependency.scala +++ b/stage2/GitDependency.scala @@ -10,6 +10,7 @@ case class GitDependency( )(implicit val logger: Logger, classLoaderCache: ClassLoaderCache, context: Context ) extends Dependency{ override def lib = new Lib(logger) + override def canBeCached = true // TODO: add support for authentication via ssh and/or https // See http://www.codeaffine.com/2014/12/09/jgit-authentication/ diff --git a/stage2/SbtDependencyDsl.scala b/stage2/SbtDependencyDsl.scala new file mode 100644 index 0000000..4fd4250 --- /dev/null +++ b/stage2/SbtDependencyDsl.scala @@ -0,0 +1,43 @@ +package cbt +trait SbtDependencyDsl{ self: Build => + /** SBT-like dependency builder DSL for syntax compatibility */ + class DependencyBuilder2( groupId: String, artifactId: String, scalaVersion: Option[String] ){ + def %(version: String) = scalaVersion.map( + v => ScalaDependency(groupId, artifactId, version, scalaVersion = v) + ).getOrElse( + MavenDependency(groupId, artifactId, version) + ) + } + implicit class DependencyBuilder(groupId: String){ + def %%(artifactId: String) = new DependencyBuilder2( groupId, artifactId, Some(scalaMajorVersion) ) + def %(artifactId: String) = new DependencyBuilder2( groupId, artifactId, None ) + } + implicit class DependencyBuilder3(d: MavenDependency){ + def %(classifier: String) = d.copy(classifier = Classifier(Some(classifier))) + } + + /* + /** SBT-like dependency builder DSL for syntax compatibility */ + implicit class DependencyBuilder0(repository: Maven){ + def %(groupId: String) = new DependencyBuilder1b(repository, groupId) + } + implicit class DependencyBuilder1a(groupId: String){ + def %%(artifactId: String) = new DependencyBuilder2( Maven.central, groupId, artifactId, Some(scalaMajorVersion) ) + def %(artifactId: String) = new DependencyBuilder2( Maven.central, groupId, artifactId, None ) + } + class DependencyBuilder1b(repository: Maven, groupId: String){ + def %%(artifactId: String) = new DependencyBuilder2( repository, groupId, artifactId, Some(scalaMajorVersion) ) + def %(artifactId: String) = new DependencyBuilder2( repository, groupId, artifactId, None ) + } + class DependencyBuilder2( repository: Maven, groupId: String, artifactId: String, scalaMajorVersion: Option[String] ){ + def %(version: String) = scalaMajorVersion.map( + v => repository(groupId, artifactId, version, scalaMajorVersion = v) + ).getOrElse( + repository.java(groupId, artifactId, version) + ) + } + implicit class DependencyBuilder3(d: MavenDependency){ + def %(classifier: String) = d.copy(classifier = Classifier(Some(classifier))) + } + */ +}
\ No newline at end of file diff --git a/stage2/mixins.scala b/stage2/mixins.scala index c3a57da..4dedd09 100644 --- a/stage2/mixins.scala +++ b/stage2/mixins.scala @@ -16,9 +16,9 @@ trait SbtTest extends Test{ trait ScalaTest extends Build with Test{ def scalaTestVersion: String - override def dependencies = Seq( + override def dependencies = super.dependencies :+ MavenRepository.central.resolve( "org.scalatest" %% "scalatest" % scalaTestVersion - ) ++ super.dependencies + ) override def run: ExitCode = { val discoveryPath = compile.toString++"/" |