@@ -6,11 +6,48 @@ import scalafix.util._
66import scalafix .util .TreePatch ._
77import scalafix .util .TokenPatch ._
88
9+ object DayDreaming {
10+
11+ val imaginaryBaseBuild = BaseBuild (
12+ context = Context ,
13+ defaultScalaVersion = " 2.12.1"
14+ )
15+ .map(addPlugin(Scalameta ))
16+ .map(addPlugin(Scalatest )) // I would expect to normally use the default test directory config
17+ .map(addPlugin(CrossBuild ))
18+ .map(addPlugin(CrossRewriter ))
19+ .map { build => // I would expect that here I would have Build with MetaBuild with ScalaTestBuild with CrossBuild with CrossRewriter
20+ build.copy(
21+ crossBuilds = Seq ( // This would be a sequence of build transforms. If I had many I would create a function to build a matrix of transforms
22+ setVersion(" 2.11.8" ) andThen
23+ addDependency(MavenDependency (" org.scalaz" , " scalaz-core" , " 7.2.10" )) andThen
24+ transformSources( // transformSources would be in CrossRewriter plugin and would apply rewrites to all sources
25+ AddGlobalImport (importer " scalaz._ " ),
26+ Replace (Symbol (" _root_.scala.package.Either." ), q " \/ " ),
27+ Replace (Symbol (" _root_.scala.util.Right." ), q " \/ - " ),
28+ RemoveGlobalImport (importer " cats.implicits._ " )
29+ ),
30+ setVersion(" 2.11.8" ) andThen
31+ addDependency(MavenDependency (" org.typelevel" , " cats" , " 0.9.0" )) andThen
32+ transformSources(AddGlobalImport (importer " cats.implicits._ " ))
33+ )
34+ )
35+ }
36+
37+ def setVersion (version : String ): Build => Build = _.copy(scalaVersion = version)
38+ def addDependency (dep : MavenDependency ): Build => Build = _.copy(dependencies = dependencies :+ dep)
39+ def removeDependency (dep : MavenDependency ): Build => Build = _.copy(dependencies = dependencies :- dep)
40+
41+ // Over time I would hope to build up a community libraryof rewrites so many of the transforms would be pulled from
42+ // a library instead of declared in the build
43+ }
44+
945class Build (val context : Context ) extends BaseBuild with Scalameta { outer =>
1046 override def defaultScalaVersion = " 2.12.1"
1147
1248 override def test : Dependency = {
1349 new BasicBuild (context) with ScalaTest {
50+ def apply = run
1451 override def dependencies = outer +: super .dependencies
1552 override def defaultScalaVersion = outer.scalaVersion
1653 override def sources = Seq (context.workingDirectory / " test" )
@@ -28,7 +65,7 @@ class Build(val context: Context) extends BaseBuild with Scalameta { outer =>
2865// case class RemoveDependency(dep: MavenDependency)
2966
3067 def versions = Seq [(String , Seq [Patch ])](
31- scalaVersion -> Seq (),
68+ // scalaVersion -> Seq(),
3269 " 2.11.8" -> Seq (
3370 RemoveGlobalImport (
3471 importer " scala.concurrent.Future "
@@ -82,7 +119,7 @@ class Build(val context: Context) extends BaseBuild with Scalameta { outer =>
82119 override def sources = {
83120 val fromTo = lib.autoRelative( outer.sources ).collect{
84121 case (location, relative) if location.isFile
85- => location -> projectDirectory / " src" / relative
122+ => location -> projectDirectory / " src" / relative
86123 }
87124
88125 val to = fromTo.map(_._2)
@@ -97,6 +134,51 @@ class Build(val context: Context) extends BaseBuild with Scalameta { outer =>
97134
98135 to
99136 }
137+
138+ override def test : Dependency = {
139+ val testDirectory = projectDirectory / " test"
140+ new BasicBuild ( context.copy(workingDirectory = testDirectory) ) with ScalaTest {
141+ // def apply = run
142+
143+ override def dependencies = outer +: super .dependencies
144+
145+ override def defaultScalaVersion = v
146+
147+ override def sources = Seq (context.workingDirectory / " test" )
148+
149+ override def projectDirectory = {
150+ val d = outer.projectDirectory / " test"
151+ d.mkdirs
152+ d
153+ }
154+ }
155+ }
156+
157+ // with
158+ // {
159+ // override def sources
160+ //
161+ // =
162+ // {
163+ // val fromTo = lib.autoRelative(outer.sources).collect {
164+ // case (location, relative) if location.isFile
165+ // => location -> projectDirectory / "src" / relative
166+ // }
167+ //
168+ // val to = fromTo.map(_._2)
169+ // assert((to diff to.distinct).isEmpty)
170+ //
171+ // Scalafix.apply(lib).config(
172+ // outer.classpath,
173+ // files = fromTo,
174+ // patches = lib_rewrites ++ version_rewrites,
175+ // allowEmpty = true
176+ // ).apply
177+ //
178+ // to
179+ // }
180+ // }
181+
100182 }
101183 }
102184 }
0 commit comments