@@ -47,11 +47,10 @@ object BuildSettings {
47
47
publishMavenStyle := true ,
48
48
publishArtifact in Test := false ,
49
49
// The Nexus repo we're publishing to.
50
- publishTo <<= version { (v : String ) =>
51
- val nexus = " https://oss.sonatype.org/"
52
- if (v.trim.endsWith(" SNAPSHOT" )) Some (" snapshots" at nexus + " content/repositories/snapshots" )
53
- else Some (" releases" at nexus + " service/local/staging/deploy/maven2" )
54
- },
50
+ publishTo := Some (
51
+ if (isSnapshot.value) " snapshots" at " https://oss.sonatype.org/content/repositories/snapshots"
52
+ else " releases" at " https://oss.sonatype.org/service/local/staging/deploy/maven2"
53
+ ),
55
54
// Maven central cannot allow other repos. We're ok here because the artifacts we
56
55
// we use externally are *optional* dependencies.
57
56
pomIncludeRepository := { x => false },
@@ -82,29 +81,20 @@ object Dependencies {
82
81
83
82
}
84
83
85
- // we cannot switch to build.sbt style here because we
86
- // do `override lazy val projects = ... tests ...`;
87
- // blocked by sbt/sbt#2532
88
-
89
- object MimaBuild extends Build {
84
+ object MimaBuild {
90
85
import BuildSettings ._
91
86
import Dependencies ._
92
87
93
- // here we list all projects that are defined.
94
- override lazy val projects = Seq (root) ++ modules ++ tests :+ reporterFunctionalTests
95
-
96
- lazy val modules = Seq (core, reporter, sbtplugin)
97
-
98
88
lazy val root = (
99
89
project(" root" , file(" ." ))
100
90
aggregate(core, reporter, sbtplugin)
101
91
settings(s3Settings:_* )
102
92
settings(name := buildName,
103
93
publish := (),
104
94
publishLocal := (),
105
- mappings in upload <<= (assembly in reporter, version) map { (cli, v) =>
106
- def loc (name : String ) = " migration-manager/%s/%s-%s.jar" format (v , name, v )
107
- Seq (cli -> loc(" migration-manager-cli" ))
95
+ mappings in upload := {
96
+ def loc (name : String ) = " migration-manager/%s/%s-%s.jar" format (version.value , name, version.value )
97
+ Seq ((assembly in reporter).value -> loc(" migration-manager-cli" ))
108
98
},
109
99
host in upload := " downloads.typesafe.com.s3.amazonaws.com" ,
110
100
testScalaVersion in Global := sys.props.getOrElse(" mima.testScalaVersion" , scalaVersion.value)
@@ -115,7 +105,7 @@ object MimaBuild extends Build {
115
105
lazy val core = (
116
106
project(" core" , file(" core" ),
117
107
settings = ((commonSettings ++ buildInfoSettings): Seq [Setting [_]]) ++: Seq (
118
- sourceGenerators in Compile < += buildInfo,
108
+ sourceGenerators in Compile += buildInfo.taskValue ,
119
109
buildInfoKeys := Seq (version),
120
110
buildInfoPackage := " com.typesafe.tools.mima.core.buildinfo" ,
121
111
buildInfoObject := " BuildInfo"
@@ -127,19 +117,14 @@ object MimaBuild extends Build {
127
117
)
128
118
129
119
val myAssemblySettings : Seq [Setting [_]] = (assemblySettings : Seq [Setting [_]]) ++ Seq (
130
- mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
131
- {
132
- case " LICENSE" => MergeStrategy .first
133
- case x => old(x)
134
- }
135
- },
136
- AssemblyKeys .excludedFiles in assembly <<= (AssemblyKeys .excludedFiles in assembly) { (old) =>
137
- val tmp : Seq [File ] => Seq [File ] = { files : Seq [File ] =>
138
- // Hack to keep LICENSE files.
139
- old(files) filterNot (_.getName contains " LICENSE" )
140
- }
141
- tmp
142
- }
120
+ mergeStrategy in assembly ~= (old => {
121
+ case " LICENSE" => MergeStrategy .first
122
+ case x => old(x)
123
+ }),
124
+ AssemblyKeys .excludedFiles in assembly ~= (old =>
125
+ // Hack to keep LICENSE files.
126
+ { files : Seq [File ] => old(files) filterNot (_.getName contains " LICENSE" ) }
127
+ )
143
128
)
144
129
145
130
lazy val reporter = (
@@ -151,7 +136,7 @@ object MimaBuild extends Build {
151
136
settings(myAssemblySettings:_* )
152
137
settings(
153
138
// add task functional-tests that depends on all functional tests
154
- functionalTests << = runAllTests,
139
+ functionalTests : = runAllTests.value ,
155
140
mainClass in assembly := Some (" com.typesafe.tools.mima.cli.Main" )
156
141
)
157
142
)
@@ -165,7 +150,7 @@ object MimaBuild extends Build {
165
150
scriptedBufferLog := false ,
166
151
// Scripted locally publishes sbt plugin and then runs test projects with locally published version.
167
152
// Therefore we also need to locally publish dependent projects on scripted test run.
168
- scripted <<= scripted dependsOn (publishLocal in core, publishLocal in reporter))
153
+ scripted := ( scripted dependsOn (publishLocal in core, publishLocal in reporter)).evaluated )
169
154
dependsOn(reporter)
170
155
settings(sbtPublishSettings:_* )
171
156
)
@@ -183,14 +168,14 @@ object MimaBuild extends Build {
183
168
184
169
// defines a Project for the given base directory (for example, functional-tests/test1)
185
170
// Its name is the directory name (test1) and it has compile+package tasks for sources in v1/ and v2/
186
- def testProject (base : File ) = project(base.name, base, settings = testProjectSettings).configs(v1Config, v2Config)
171
+ def testProject (base : File ) = project(" test- " + base.name, base, settings = testProjectSettings).configs(v1Config, v2Config)
187
172
188
173
lazy val testProjectSettings =
189
174
commonSettings ++ // normal project defaults; can be trimmed later- test and run aren't needed, for example.
190
- Seq (scalaVersion <<= testScalaVersion in Global ) ++
175
+ Seq (scalaVersion := ( testScalaVersion in Global ).value ) ++
191
176
inConfig(v1Config)(perConfig) ++ // add compile/package for the v1 sources
192
177
inConfig(v2Config)(perConfig) :+ // add compile/package for the v2 sources
193
- (functionalTests << = runTest) // add the functional-tests task
178
+ (functionalTests : = runTest.value ) // add the functional-tests task
194
179
195
180
// this is the key for the task that runs the reporter's functional tests
196
181
lazy val functionalTests = TaskKey [Unit ](" test-functional" )
@@ -211,65 +196,68 @@ object MimaBuild extends Build {
211
196
// sets the source directory in this configuration to be: testN / vN
212
197
// scalaSource is the setting key that defines the directory for Scala sources
213
198
// configuration gets the current configuration
214
- // expanded version: ss <<= (bd, conf) apply { (b,c) => b / c.name }
215
- lazy val shortSourceDir = scalaSource <<= (baseDirectory, configuration) { _ / _.name }
216
-
217
- // this is the custom test task of the form (ta, tb, tc) map { (a,b,c) => ... }
218
- // tx are the tasks we need to do our job.
219
- // Once the task engine runs these tasks, it evaluates the function supplied to map with the task results bound to
220
- // a,b,c
221
- lazy val runTest =
222
- (fullClasspath in (reporterFunctionalTests, Compile ), // the test classpath from the functionalTest project for the test
223
- thisProjectRef, // gives us the ProjectRef this task is defined in
224
- scalaInstance in core, // get a reference to the already loaded Scala classes so we get the advantage of a warm jvm
225
- packageBin in v1Config, // package the v1 sources and get the configuration used
226
- packageBin in v2Config, // same for v2
227
- scalaVersion,
228
- streams) map { (cp, proj, si, v1, v2, scalaV, streams) =>
229
- val urls = Attributed .data(cp).map(_.toURI.toURL).toArray
230
- val loader = new java.net.URLClassLoader (urls, si.loader)
231
-
232
- val testClass = loader.loadClass(" com.typesafe.tools.mima.lib.CollectProblemsTest" )
233
- val testRunner = testClass.newInstance().asInstanceOf [{
234
- def runTest (testClasspath : Array [String ], testName : String , oldJarPath : String , newJarPath : String , oraclePath : String ): Unit
235
- }]
236
-
237
- // Add the scala-library to the MiMa classpath used to run this test
238
- val testClasspath = Attributed .data(cp).filter(_.getName endsWith " scala-library.jar" ).map(_.getAbsolutePath).toArray
239
-
240
- val projectPath = proj.build.getPath + " reporter" + " /" + " functional-tests" + " /" + " src" + " /" + " test" + " /" + proj.project
241
-
242
- val oraclePath = {
243
- val p = projectPath + " /problems.txt"
244
- val p212 = projectPath + " /problems-2.12.txt"
245
- if (! (scalaV.startsWith(" 2.10." ) || scalaV.startsWith(" 2.11." )) && new java.io.File (p212).exists) p212
246
- else p
247
- }
248
-
249
- try {
250
- import scala .language .reflectiveCalls
251
- testRunner.runTest(testClasspath, proj.project, v1.getAbsolutePath, v2.getAbsolutePath, oraclePath)
252
- streams.log.info(" Test '" + proj.project + " ' succeeded." )
253
- } catch {
254
- case e : Exception => sys.error(e.toString)
255
- }
256
- ()
257
- }
258
-
259
- lazy val runAllTests =
260
- (state, // this is how we access all defined projects from a task
261
- thisProjectRef, // gives us the ProjectRef this task is defined in
262
- test in Test // requires unit tests to run first
263
- ) flatMap { (s, proj, _) =>
264
- // gets all defined projects, dropping this project (core) so the task doesn't depend on itself
265
- val structure = Project .structure(s)
266
- val allProjects = structure.units(proj.build).defined.values filter (_.id != proj.project)
267
- // get the fun-tests task in each project
268
- val allTests = allProjects.toSeq flatMap { p => functionalTests in ProjectRef (proj.build, p.id) get structure.data }
269
- // depend on all fun-tests
270
- allTests.join.map(_ => ())
271
- }
272
-
273
- def project (id : String , base : File , settings : Seq [Def .Setting [_]] = Nil ) =
274
- Project (id, base, settings = settings) disablePlugins(BintrayPlugin )
199
+ lazy val shortSourceDir = scalaSource := baseDirectory.value / configuration.value.name
200
+
201
+ lazy val runTest = Def .task {
202
+ val cp = (fullClasspath in (reporterFunctionalTests, Compile )).value // the test classpath from the functionalTest project for the test
203
+ val proj = thisProjectRef.value // gives us the ProjectRef this task is defined in
204
+ val si = (scalaInstance in core).value // get a reference to the already loaded Scala classes so we get the advantage of a warm jvm
205
+ val v1 = (packageBin in v1Config).value // package the v1 sources and get the configuration used
206
+ val v2 = (packageBin in v2Config).value // same for v2
207
+ val scalaV = scalaVersion.value
208
+ val streams = Keys .streams.value
209
+ val urls = Attributed .data(cp).map(_.toURI.toURL).toArray
210
+ val loader = new java.net.URLClassLoader (urls, si.loader)
211
+
212
+ val testClass = loader.loadClass(" com.typesafe.tools.mima.lib.CollectProblemsTest" )
213
+ val testRunner = testClass.newInstance().asInstanceOf [{
214
+ def runTest (testClasspath : Array [String ], testName : String , oldJarPath : String , newJarPath : String , oraclePath : String ): Unit
215
+ }]
216
+
217
+ // Add the scala-library to the MiMa classpath used to run this test
218
+ val testClasspath = Attributed .data(cp).filter(_.getName endsWith " scala-library.jar" ).map(_.getAbsolutePath).toArray
219
+
220
+ val projectPath = proj.build.getPath + " reporter" + " /" + " functional-tests" + " /" + " src" + " /" + " test" + " /" + proj.project.stripPrefix(" test-" )
221
+
222
+ val oraclePath = {
223
+ val p = projectPath + " /problems.txt"
224
+ val p212 = projectPath + " /problems-2.12.txt"
225
+ if (! (scalaV.startsWith(" 2.10." ) || scalaV.startsWith(" 2.11." )) && new java.io.File (p212).exists) p212
226
+ else p
227
+ }
228
+
229
+ try {
230
+ import scala .language .reflectiveCalls
231
+ testRunner.runTest(testClasspath, proj.project, v1.getAbsolutePath, v2.getAbsolutePath, oraclePath)
232
+ streams.log.info(" Test '" + proj.project + " ' succeeded." )
233
+ } catch {
234
+ case e : Exception => sys.error(e.toString)
235
+ }
236
+ ()
237
+ }
238
+
239
+ lazy val runAllTests = Def .taskDyn {
240
+ val s = state.value // this is how we access all defined projects from a task
241
+ val proj = thisProjectRef.value // gives us the ProjectRef this task is defined in
242
+ val _ = (test in Test ).value // requires unit tests to run first
243
+
244
+ // gets all defined projects, dropping this project (core) so the task doesn't depend on itself
245
+ val structure = Project .structure(s)
246
+ val allProjects = structure.units(proj.build).defined.values filter (_.id != proj.project)
247
+
248
+ // get the fun-tests task in each project
249
+ val allTests = allProjects.toSeq flatMap { p => functionalTests in ProjectRef (proj.build, p.id) get structure.data }
250
+
251
+ // depend on all fun-tests
252
+ Def .task {
253
+ allTests.join.map(_ => ()).value
254
+ }
255
+ }
256
+
257
+ def project (id : String , base : File , settings : Seq [Def .Setting [_]] = Nil ) =
258
+ Project (id, base, settings = settings) disablePlugins(BintrayPlugin )
259
+ }
260
+
261
+ object DefineTestProjectsPlugin extends AutoPlugin {
262
+ override def extraProjects = MimaBuild .tests
275
263
}
0 commit comments