Skip to content

Commit d2090af

Browse files
Compiles with sbt 1.0 and sbt 0.13
1. ascii-graphs We need a 2.12 version of ascii-graphs. The last commit to the project is in June 2013 (https://github.com/mdr/ascii-graphs/graphs/contributors). We are now in October 2017. I opened a PR (mdr/ascii-graphs#11) but I don't expect any progress on this front. We can maintain a fork or drop ascii-graphs. 2. ignoreMissingUpdate ignoreMissingUpdate is a tricky one. Here is some explanation: we need to duplicate the updateTask in sbt it's define as: ```scala def updateTask: Initialize[Task[UpdateReport]] = Def.task { // ... val uc0 = updateConfiguration.value // ... } ``` since it's not scoped to our task (ex: `updateConfiguration in ignoreMissingUpdate`) we cannot just do ```scala updateConfiguration in ignoreMissingUpdate := { updateConfiguration.value.withMissingOk(true) } ``` For example, the following example yield `"u2: false" ``` val update2 = TaskKey[Unit]("update2", "...") val update2Configuration = SettingKey[Boolean]("...") update2 := Def.task { val u2 = (update2Configuration in update2).value println(s"u2: $u2") }.value update2Configuration := false update2Configuration in update2 := true ``` 3. cross publishing We can use the ^ operator to publish. For example: `sbt "^ publish"` to publish for both sbt 0.13 and 1.0.
1 parent 8591a5a commit d2090af

File tree

17 files changed

+299
-77
lines changed

17 files changed

+299
-77
lines changed

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ sudo: false
22
language: scala
33
jdk: oraclejdk7
44
script:
5-
- sbt test scripted
5+
# pending https://github.com/mdr/ascii-graphs/pull/11
6+
- git clone git://github.com/MasseGuillaume/ascii-graphs.git
7+
- pushd ascii-graphs
8+
- sbt + publishLocal
9+
- popd
10+
11+
- sbt ";^test ;^scripted"
12+

build.sbt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
ScriptedPlugin.scriptedSettings
22

33
libraryDependencies ++= Seq(
4-
"com.github.mdr" %% "ascii-graphs" % "0.0.3",
5-
"org.specs2" %% "specs2" % "2.3.11" % Test
4+
"com.github.mdr" %% "ascii-graphs" % "0.0.7-SNAPSHOT",
5+
"org.specs2" %% "specs2-core" % "3.9.5" % Test
66
)
77

8+
libraryDependencies += Defaults.sbtPluginExtra(
9+
"com.dwijnand" % "sbt-compat" % "1.1.0",
10+
(sbtBinaryVersion in pluginCrossBuild).value,
11+
(scalaBinaryVersion in update).value
12+
)
13+
14+
crossSbtVersions := List("0.13.16", "1.0.2")
15+
816
scalacOptions ++= Seq(
917
"-deprecation",
1018
"-encoding",
@@ -14,3 +22,6 @@ scalacOptions ++= Seq(
1422
)
1523

1624
ScalariformSupport.formatSettings
25+
26+
addCommandAlias("c1", ";cls;^^ 1.0.2;compile")
27+
addCommandAlias("c0", ";cls;^^ 0.13.16;compile")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.virtualvoid.sbt.graph
2+
3+
import sbt._
4+
import Keys._
5+
6+
import CrossVersion._
7+
import DependencyGraphKeys._
8+
9+
object compat {
10+
def convertConfig(config: sbt.Configuration): String = {
11+
config.toString
12+
}
13+
14+
/**
15+
* This is copied directly from sbt/main/Defaults.java and then changed to update the UpdateConfiguration
16+
* to ignore missing artifacts.
17+
*/
18+
def ingnoreMissingSettings: Seq[Setting[_]] = Seq(
19+
updateConfiguration in ignoreMissingUpdate := {
20+
val config = updateConfiguration.value
21+
new UpdateConfiguration(config.retrieve, true, config.logging)
22+
},
23+
ignoreMissingUpdate := sbt.Compat.updateTask(ignoreMissingUpdate).value
24+
)
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2015 Johannes Rudolph
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.virtualvoid.sbt.graph
18+
19+
import sbinary.{ Format, DefaultProtocol }
20+
21+
object ModuleGraphProtocol extends DefaultProtocol {
22+
implicit def seqFormat[T: Format]: Format[Seq[T]] = wrap[Seq[T], List[T]](_.toList, _.toSeq)
23+
implicit val ModuleIdFormat: Format[ModuleId] = asProduct3(ModuleId)(ModuleId.unapply(_).get)
24+
implicit val ModuleFormat: Format[Module] = asProduct6(Module)(Module.unapply(_).get)
25+
implicit val ModuleGraphFormat: Format[ModuleGraph] = asProduct2(ModuleGraph.apply _)(ModuleGraph.unapply(_).get)
26+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package sbt
2+
3+
import Keys._
4+
import Def.Initialize
5+
6+
import CrossVersion.partialVersion
7+
8+
object Compat {
9+
10+
// https://github.com/sbt/sbt/blob/e3c4db5ae80fa3e2a40b7a81bee0822e49f76aaf/main/src/main/scala/sbt/Defaults.scala#L1471
11+
def updateTask(task: TaskKey[_]): Initialize[Task[UpdateReport]] = Def.task {
12+
val depsUpdated = transitiveUpdate.value.exists(!_.stats.cached)
13+
val isRoot = executionRoots.value contains resolvedScoped.value
14+
val s = streams.value
15+
val scalaProvider = appConfiguration.value.provider.scalaProvider
16+
17+
// Only substitute unmanaged jars for managed jars when the major.minor parts of the versions the same for:
18+
// the resolved Scala version and the scalaHome version: compatible (weakly- no qualifier checked)
19+
// the resolved Scala version and the declared scalaVersion: assume the user intended scalaHome to override anything with scalaVersion
20+
def subUnmanaged(subVersion: String, jars: Seq[File]) = (sv: String)
21+
(partialVersion(sv), partialVersion(subVersion), partialVersion(scalaVersion.value)) match {
22+
case (Some(res), Some(sh), _) if res == sh jars
23+
case (Some(res), _, Some(decl)) if res == decl jars
24+
case _ Nil
25+
}
26+
27+
val subScalaJars: String Seq[File] = SbtAccess.unmanagedScalaInstanceOnly.value match {
28+
case Some(si) subUnmanaged(si.version, si.allJars)
29+
case None sv if (scalaProvider.version == sv) scalaProvider.jars else Nil
30+
}
31+
32+
val transform: UpdateReport UpdateReport =
33+
r Classpaths.substituteScalaFiles(scalaOrganization.value, r)(subScalaJars)
34+
35+
val show = Reference.display(thisProjectRef.value)
36+
37+
Classpaths.cachedUpdate(
38+
cacheFile = s.cacheDirectory,
39+
label = show,
40+
module = ivyModule.value,
41+
config = (updateConfiguration in task).value,
42+
transform = transform,
43+
skip = (skip in update).value,
44+
force = isRoot,
45+
depsUpdated = depsUpdated,
46+
log = s.log)
47+
}
48+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.virtualvoid.sbt.graph
2+
3+
import DependencyGraphKeys._
4+
5+
import sbt._
6+
import Keys._
7+
8+
object compat {
9+
def convertConfig(config: sbt.Configuration): sbt.Configuration = {
10+
config
11+
}
12+
13+
val ingnoreMissingSettings: Seq[Setting[_]] = Seq(
14+
updateConfiguration in ignoreMissingUpdate := {
15+
updateConfiguration.value.withMissingOk(true)
16+
},
17+
ignoreMissingUpdate := sbt.Compat.updateTask(ignoreMissingUpdate).value
18+
)
19+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2015 Johannes Rudolph
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.virtualvoid.sbt.graph
18+
19+
import sjsonnew._, LList.:*:
20+
21+
object ModuleGraphProtocol extends BasicJsonProtocol {
22+
23+
implicit val ModuleIdFormat: IsoLList[ModuleId] =
24+
LList.isoCurried(
25+
(m: ModuleId) =>
26+
("organisation", m.organisation) :*:
27+
("name", m.name) :*:
28+
("version", m.version) :*:
29+
LNil
30+
) { case
31+
(_, organisation) :*:
32+
(_, name) :*:
33+
(version, _) :*:
34+
LNil => ModuleId(organisation, name, version)
35+
}
36+
37+
implicit val ModuleFormat: IsoLList[Module] =
38+
LList.isoCurried(
39+
(m: Module) =>
40+
("id", m.id) :*:
41+
("license", m.license) :*:
42+
("extraInfo", m.extraInfo) :*:
43+
("evictedByVersion", m.evictedByVersion) :*:
44+
("jarFile", m.jarFile) :*:
45+
("error", m.error) :*:
46+
LNil
47+
) {
48+
case
49+
(_, id) :*:
50+
(_, license) :*:
51+
(_, extraInfo) :*:
52+
(_, evictedByVersion) :*:
53+
(_, jarFile) :*:
54+
(_, error) :*:
55+
LNil => Module(id, license, extraInfo, evictedByVersion, jarFile, error)
56+
}
57+
58+
59+
implicit val ModuleGraphFormat: IsoLList[ModuleGraph] =
60+
LList.isoCurried(
61+
(g: ModuleGraph) =>
62+
("nodes", g.nodes) :*:
63+
("edges", g.edges) :*:
64+
LNil
65+
) { case
66+
(_, nodes) :*:
67+
(_, edges) :*:
68+
LNil => ModuleGraph(nodes, edges)
69+
}
70+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package sbt
2+
3+
import Keys._
4+
import Def.Initialize
5+
6+
import CrossVersion.partialVersion
7+
import sbt.internal.LibraryManagement
8+
9+
object Compat {
10+
11+
// https://github.com/sbt/sbt/blob/4ce4fb72bde3b8acfaf526b79d32ca1463bc687b/main/src/main/scala/sbt/Defaults.scala#L2298
12+
def updateTask(task: TaskKey[_]): Initialize[Task[UpdateReport]] = Def.task {
13+
val depsUpdated = transitiveUpdate.value.exists(!_.stats.cached)
14+
val isRoot = executionRoots.value contains resolvedScoped.value
15+
val s = streams.value
16+
val scalaProvider = appConfiguration.value.provider.scalaProvider
17+
18+
// Only substitute unmanaged jars for managed jars when the major.minor parts of the versions the same for:
19+
// the resolved Scala version and the scalaHome version: compatible (weakly- no qualifier checked)
20+
// the resolved Scala version and the declared scalaVersion: assume the user intended scalaHome to override anything with scalaVersion
21+
def subUnmanaged(subVersion: String, jars: Seq[File]) = (sv: String)
22+
(partialVersion(sv), partialVersion(subVersion), partialVersion(scalaVersion.value)) match {
23+
case (Some(res), Some(sh), _) if res == sh jars
24+
case (Some(res), _, Some(decl)) if res == decl jars
25+
case _ Nil
26+
}
27+
28+
val subScalaJars: String Seq[File] = SbtAccess.unmanagedScalaInstanceOnly.value match {
29+
case Some(si) subUnmanaged(si.version, si.allJars)
30+
case None sv if (scalaProvider.version == sv) scalaProvider.jars else Nil
31+
}
32+
33+
val transform: UpdateReport UpdateReport =
34+
r Classpaths.substituteScalaFiles(scalaOrganization.value, r)(subScalaJars)
35+
36+
val evictionOptions = Def.taskDyn {
37+
if (executionRoots.value.exists(_.key == evicted.key))
38+
Def.task(EvictionWarningOptions.empty)
39+
else Def.task((evictionWarningOptions in update).value)
40+
}.value
41+
42+
LibraryManagement.cachedUpdate(
43+
// LM API
44+
lm = dependencyResolution.value,
45+
// Ivy-free ModuleDescriptor
46+
module = ivyModule.value,
47+
s.cacheStoreFactory.sub(updateCacheName.value),
48+
Reference.display(thisProjectRef.value),
49+
(updateConfiguration in task).value,
50+
transform = transform,
51+
skip = (skip in update).value,
52+
force = isRoot,
53+
depsUpdated = transitiveUpdate.value.exists(!_.stats.cached),
54+
uwConfig = (unresolvedWarningConfiguration in update).value,
55+
ewo = evictionOptions,
56+
mavenStyle = publishMavenStyle.value,
57+
compatWarning = compatibilityWarningOptions.value,
58+
log = s.log
59+
)
60+
}
61+
}
62+

0 commit comments

Comments
 (0)