diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-06 22:16:46 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-04-06 22:51:51 -0400 |
commit | a63b6d3ea52d0badb07c2c003f98e77bee7cbdda (patch) | |
tree | 517b43916adfc3a0e4ac6a1f52176b135d052d43 | |
parent | 0195249ebf44bf0f797a976d884350f963982ec1 (diff) | |
download | cbt-a63b6d3ea52d0badb07c2c003f98e77bee7cbdda.tar.gz cbt-a63b6d3ea52d0badb07c2c003f98e77bee7cbdda.tar.bz2 cbt-a63b6d3ea52d0badb07c2c003f98e77bee7cbdda.zip |
Correctly interact with build in cwd instead of loading it's managed build in case of a BuildBuild.
-rw-r--r-- | TODO.txt | 1 | ||||
-rw-r--r-- | stage1/Stage1Lib.scala | 2 | ||||
-rw-r--r-- | stage2/BasicBuild.scala | 4 | ||||
-rw-r--r-- | stage2/BuildBuild.scala | 8 | ||||
-rw-r--r-- | stage2/BuildDependency.scala | 4 | ||||
-rw-r--r-- | stage2/GitDependency.scala | 2 | ||||
-rw-r--r-- | stage2/Lib.scala | 18 | ||||
-rw-r--r-- | stage2/Stage2.scala | 7 | ||||
-rw-r--r-- | test/test.scala | 2 |
9 files changed, 23 insertions, 25 deletions
@@ -3,7 +3,6 @@ TODO: - improve logging - immediate features - - maybe rename context.cwd - fix main project main method being run during tests - investigate and solve multiple compilations of the same SourceDependency Build. Maybe introduce global Build map. diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala index da9f8dd..7a2f8db 100644 --- a/stage1/Stage1Lib.scala +++ b/stage1/Stage1Lib.scala @@ -31,7 +31,7 @@ object CatchTrappedExitCode{ } } -case class Context( cwd: File, args: Seq[String], logger: Logger, cbtHasChanged: Boolean, classLoaderCache: ClassLoaderCache ) +case class Context( projectDirectory: File, cwd: File, args: Seq[String], logger: Logger, cbtHasChanged: Boolean, classLoaderCache: ClassLoaderCache ) class BaseLib{ def realpath(name: File) = new File(Paths.get(name.getAbsolutePath).normalize.toString) diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index 39cc9e3..f785f01 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -23,7 +23,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop with SbtDe override def canBeCached = false def enableConcurrency = false - final def projectDirectory: File = lib.realpath(context.cwd) + final def projectDirectory: File = lib.realpath(context.projectDirectory) assert( projectDirectory.exists, "projectDirectory does not exist: " ++ projectDirectory.string ) final def usage: String = lib.usage(this.getClass, context) @@ -89,7 +89,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop with SbtDe ) = lib.ScalaDependency( groupId, artifactId, version, classifier, scalaVersion ) final def BuildDependency(path: File) = cbt.BuildDependency( - context.copy( cwd = path, args = Seq() ) + context.copy( projectDirectory = path, args = Seq() ) ) def triggerLoopFiles: Seq[File] = sources ++ transitiveDependencies.collect{ case b: TriggerLoop => b.triggerLoopFiles }.flatten diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala index 813b44b..6435bcd 100644 --- a/stage2/BuildBuild.scala +++ b/stage2/BuildBuild.scala @@ -6,11 +6,11 @@ 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 = try{ - val managedContext = context.copy( cwd = managedBuildDirectory ) val cl = new cbt.URLClassLoader( exportedClasspath, classOf[BuildBuild].getClassLoader // FIXME: this looks wrong. Should be ClassLoader.getSystemClassLoader but that crashes ) + val managedContext = context.copy( projectDirectory = managedBuildDirectory ) cl .loadClass(lib.buildClassName) .getConstructor(classOf[Context]) @@ -18,10 +18,10 @@ class BuildBuild(context: Context) extends Build(context){ .asInstanceOf[Build] } catch { case e: ClassNotFoundException if e.getMessage == lib.buildClassName => - throw new Exception("You need to remove the directory or define a class Build in: "+context.cwd) + throw new Exception("You need to remove the directory or define a class Build in: "+context.projectDirectory) case e: Exception => - throw new Exception("during build: "+context.cwd, e) + throw new Exception("during build: "+context.projectDirectory, e) } override def triggerLoopFiles = super.triggerLoopFiles ++ managedBuild.triggerLoopFiles - override def finalBuild = managedBuild.finalBuild + override def finalBuild = if( context.projectDirectory == context.cwd ) this else managedBuild.finalBuild } diff --git a/stage2/BuildDependency.scala b/stage2/BuildDependency.scala index 19357f9..8965cee 100644 --- a/stage2/BuildDependency.scala +++ b/stage2/BuildDependency.scala @@ -16,7 +16,7 @@ trait TriggerLoop extends Dependency{ } /** You likely want to use the factory method in the BasicBuild class instead of this. */ case class BuildDependency(context: Context) extends TriggerLoop{ - override def show = this.getClass.getSimpleName ++ "(" ++ context.cwd.string ++ ")" + override def show = this.getClass.getSimpleName ++ "(" ++ context.projectDirectory.string ++ ")" final override lazy val logger = context.logger final override lazy val lib: Lib = new Lib(logger) private val root = lib.loadRoot( context.copy(args=Seq()) ) @@ -31,7 +31,7 @@ case class BuildDependency(context: Context) extends TriggerLoop{ } /* case class DependencyOr(first: BuildDependency, second: JavaDependency) extends ProjectProxy with BuildDependencyBase{ - val isFirst = new File(first.context.cwd).exists + val isFirst = new File(first.context.projectDirectory).exists def triggerLoopFiles = if(isFirst) first.triggerLoopFiles else Seq() protected val delegate = if(isFirst) first else second } diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala index 27bf253..16423df 100644 --- a/stage2/GitDependency.scala +++ b/stage2/GitDependency.scala @@ -38,7 +38,7 @@ case class GitDependency( } val managedBuild = lib.loadDynamic( - context.copy( cwd = checkoutDirectory, args = Seq() ) + context.copy( projectDirectory = checkoutDirectory, args = Seq() ) ) Seq( managedBuild ) } diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 6b6263c..dbd6108 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -34,19 +34,19 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ This can either the Build itself, of if exists a BuildBuild or a BuildBuild for a BuildBuild and so on. */ def loadRoot(context: Context, default: Context => Build = new Build(_)): Build = { - context.logger.composition( context.logger.showInvocation("Build.loadRoot",context) ) - def findStartDir(cwd: File): File = { - val buildDir = realpath( cwd ++ "/build" ) - if(buildDir.exists) findStartDir(buildDir) else cwd + context.logger.composition( context.logger.showInvocation("Build.loadRoot",context.projectDirectory) ) + def findStartDir(projectDirectory: File): File = { + val buildDir = realpath( projectDirectory ++ "/build" ) + if(buildDir.exists) findStartDir(buildDir) else projectDirectory } - val start = findStartDir(context.cwd) + val start = findStartDir(context.projectDirectory) - val useBasicBuildBuild = context.cwd == start + val useBasicBuildBuild = context.projectDirectory == start val rootBuildClassName = if( useBasicBuildBuild ) buildBuildClassName else buildClassName try{ - if(useBasicBuildBuild) default( context ) else new cbt.BuildBuild( context.copy( cwd = start ) ) + if(useBasicBuildBuild) default( context ) else new cbt.BuildBuild( context.copy( projectDirectory = start ) ) } catch { case e:ClassNotFoundException if e.getMessage == rootBuildClassName => throw new Exception(s"no class $rootBuildClassName found in " ++ start.string) @@ -110,7 +110,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ logger.lib(s"invoke testDefault( $context )") val exitCode: ExitCode = loadDynamic( - context.copy( cwd = context.cwd ++ "/test", args = loggerArg.toVector ++ context.args ), + context.copy( projectDirectory = context.projectDirectory ++ "/test", args = loggerArg.toVector ++ context.args ), new Build(_) with mixins.Test ).run logger.lib(s"return testDefault( $context )") @@ -145,7 +145,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ ( ( if( thisTasks.nonEmpty ){ - s"""Methods provided by Build ${context.cwd} + s"""Methods provided by Build ${context.projectDirectory} ${thisTasks.mkString(" ")} diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala index 4ae149c..0856f54 100644 --- a/stage2/Stage2.scala +++ b/stage2/Stage2.scala @@ -22,8 +22,8 @@ object Stage2 extends Stage2Base{ 0 } val task = args.args.lift( taskIndex ) - - val context = Context( args.cwd, args.args.drop( taskIndex ), logger, args.cbtHasChanged, new ClassLoaderCache(logger) ) + + val context = Context( args.cwd, args.cwd, args.args.drop( taskIndex ), logger, args.cbtHasChanged, new ClassLoaderCache(logger) ) val first = lib.loadRoot( context ) val build = first.finalBuild @@ -44,9 +44,8 @@ object Stage2 extends Stage2Base{ case file if triggerFiles.exists(file.toString startsWith _.toString) => val build = lib.loadDynamic(context) - val reflectBuild = new lib.ReflectBuild( build ) logger.loop(s"Re-running $task for " ++ build.projectDirectory.toString) - reflectBuild.callNullary(task) + new lib.ReflectBuild(build).callNullary(task) } } else { new lib.ReflectBuild(build).callNullary(task) diff --git a/test/test.scala b/test/test.scala index 7bd2c6a..29e6afa 100644 --- a/test/test.scala +++ b/test/test.scala @@ -72,7 +72,7 @@ object Main{ logger.test( "Running tests " ++ _args.toList.toString ) { - val noContext = Context(cbtHome ++ "/test/nothing", Seq(), logger, false, new ClassLoaderCache(logger)) + val noContext = Context(cbtHome ++ "/test/nothing", cbtHome, Seq(), logger, false, new ClassLoaderCache(logger)) val b = new Build(noContext){ override def dependencies = Seq( MavenRepository.central.resolve( |