diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2017-02-19 19:14:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-19 19:14:48 +0800 |
commit | 48f5f394798795e682a3acaa197d47ccf6bcde61 (patch) | |
tree | 81cd8b9085b39d1ff1fec60b0261e592208503a7 | |
parent | cf1cf8678e7ad5366c9ac40451cfa9353bd8b7f3 (diff) | |
parent | 2f2035682a942814a4a3e34dc4e61c34d00c1fa7 (diff) | |
download | cbt-48f5f394798795e682a3acaa197d47ccf6bcde61.tar.gz cbt-48f5f394798795e682a3acaa197d47ccf6bcde61.tar.bz2 cbt-48f5f394798795e682a3acaa197d47ccf6bcde61.zip |
Merge pull request #349 from cvogt/chris3
various minor changes
-rw-r--r-- | README.md | 33 | ||||
-rw-r--r-- | stage2/BuildBuild.scala | 2 | ||||
-rw-r--r-- | stage2/Lib.scala | 6 |
3 files changed, 38 insertions, 3 deletions
@@ -495,3 +495,36 @@ only show first 20 lines of type errors to catch the root ones ``` cbt c 2>&1 | head -n 20 ``` + +Inheritance Pittfalls +--------------------- +``` +trait Shared extends BaseBuild{ + // this lowers the type from Seq[Dependency] to Seq[DirectoryDependency] + override def dependencies = Seq( DirectoryDependency(...) ) +} +class Build(...) extends Shared{ + // this now fails because GitDependency is not a DirectoryDependency + override def dependencies = Seq( GitDependency(...) ) +} +// Solution: raise the type explicitly +trait Shared extends BaseBuild{ + // this lowers the type from Seq[Dependency] to Seq[DirectoryDependency] + override def dependencies: Seq[Dependency] = Seq( DirectoryDependency(...) ) +} +``` + +``` +trait Shared extends BaseBuild{ + override def dependencies: Seq[Dependency] = Seq() // removes all dependencies, does not inclide super.dependencies +} +trait SomePlugin extends BaseBuild{ + // adds a dependency + override def dependencies: Seq[Dependency] = super.dependencies ++ Seq( baz ) +} +class Build(...) extends Shared with SomePlugin{ + // dependencies does now contain baz here, which can be surprising +} +// Solution can be being careful about the order and using traits instead of classes for mixins +class Build(...) extends SomePlugin with Shared +``` diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala index 9ac631f..d97e186 100644 --- a/stage2/BuildBuild.scala +++ b/stage2/BuildBuild.scala @@ -2,6 +2,8 @@ package cbt import java.nio.file._ import java.io.File +class ConcreteBuildBuild(val context: Context) extends BuildBuild +class ConcreteBuildBuildWithoutEssentials(val context: Context) extends BuildBuildWithoutEssentials trait BuildBuild extends BuildBuildWithoutEssentials{ override def dependencies = super.dependencies :+ plugins.essentials diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 9e1f824..7adb33e 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -47,9 +47,9 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ || directory == (context.cbtHome ++ "/libraries/eval") || directory == (context.cbtHome ++ "/plugins/scalatest") ) - new cbt.BasicBuild( context.copy( workingDirectory = start ) ) with BuildBuildWithoutEssentials + new cbt.ConcreteBuildBuildWithoutEssentials( context.copy( workingDirectory = start ) ) else - new cbt.BasicBuild( context.copy( workingDirectory = start ) ) with BuildBuild + new cbt.ConcreteBuildBuild( context.copy( workingDirectory = start ) ) } catch { case e:ClassNotFoundException if e.getMessage == buildClassName => throw new Exception(s"no class ${buildClassName} found in " ++ start.string) @@ -139,7 +139,7 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ ( ( if( thisTasks.nonEmpty ){ - s"""Methods provided by Build ${show} + s"""Methods provided by ${show} ${thisTasks.mkString(" ")} |