Skip to content

Commit 4159461

Browse files
committed
Merge branch 'main' into update/scopt-4.0.1
2 parents 9c39ecf + 40f3879 commit 4159461

File tree

12 files changed

+202
-126
lines changed

12 files changed

+202
-126
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,15 @@ jobs:
5252
- name: Check that workflows are up to date
5353
run: sbt ++${{ matrix.scala }} githubWorkflowCheck
5454

55-
- name: Check formatting and style
56-
run: sbt ++${{ matrix.scala }} scalafmtCheckAll scalastyle
57-
58-
- name: Check version adheres to the policy
59-
run: sbt ++${{ matrix.scala }} versionPolicyCheck
60-
61-
- name: Check documentation has been generated
62-
run: sbt ++${{ matrix.scala }} mdocCheck
63-
64-
- name: Check dependencies
65-
run: sbt ++${{ matrix.scala }} evicted undeclaredCompileDependenciesTest unusedCompileDependenciesTest dependencyCheckAggregate
66-
67-
- name: Build and test
68-
run: sbt ++${{ matrix.scala }} test
55+
- name: Build, test and check libraries
56+
run: sbt ++${{ matrix.scala }} check
6957

7058
- name: Build and test sbt plugin
7159
if: matrix.scala == '2.12.13'
7260
run: sbt ++${{ matrix.scala }} scripted
7361

7462
- name: Compress target directories
75-
run: tar cf targets.tar sbt/target target doc-templates/target cli/target core/target project/target
63+
run: tar cf targets.tar sbt/target target doc-templates/target cli/target core/target example/target project/target
7664

7765
- name: Upload target directories
7866
uses: actions/upload-artifact@v2

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Scala2PlantUML
22

3-
[![Continuous Integration](https://github.com/BotTech/scala2plantuml/actions/workflows/ci.yml/badge.svg)](https://github.com/BotTech/scala2plantuml/actions/workflows/ci.yml)
4-
![Scala2PlantUML Version](https://img.shields.io/maven-central/v/nz.co.bottech/scala2plantuml_2.13?label=Scala2PlantUML)
3+
[![Build badge](https://img.shields.io/github/workflow/status/BotTech/scala2plantuml/Continuous%20Integration/main)](https://github.com/BotTech/scala2plantuml/actions/workflows/ci.yml)
4+
[![Maven-Central badge](https://img.shields.io/maven-central/v/nz.co.bottech/scala2plantuml_2.13)](https://search.maven.org/search?q=g:nz.co.bottech%20a:*scala2plantuml*)
5+
[![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org)
56

67
Scala2PlantUML generates [PlantUML] diagrams from Scala code.
78

@@ -52,6 +53,7 @@ cs install --channel https://git.io/Jqv1i scala2plantuml
5253
### Usage
5354

5455
```text
56+
> scala2plantuml --help
5557
Scala2PlantUML version 0.1.12
5658
Usage: scala2plantuml [options] symbol
5759

build.sbt

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,31 @@ val supportedScalaVersions = List(scala212, scala213)
44

55
val logbackVersion = "1.2.3"
66
val scalaCollectionCompatibilityVersion = "2.3.2"
7-
val scoptVersion = "4.0.1"
7+
val scoptVersion = "4.0.0"
8+
val sdbVersion = "4.4.10"
89
val slf4jVersion = "1.7.30"
910
val utestVersion = "0.7.7"
1011

11-
val checkTasks = List(
12-
"scalafmtCheckAll",
13-
"scalastyle",
14-
"versionPolicyCheck",
15-
"githubWorkflowCheck",
16-
"mdocCheck",
17-
"evicted",
18-
"undeclaredCompileDependenciesTest",
19-
"unusedCompileDependenciesTest",
20-
"dependencyCheckAggregate",
21-
"test",
22-
"scripted"
23-
)
24-
2512
addCommandAlias(
26-
"check",
13+
"devCheck",
2714
supportedScalaVersions.flatMap { version =>
28-
s"++$version" :: checkTasks.filterNot(_ == "scripted" && version == scala213)
29-
}.mkString("; ")
15+
s"++$version" :: "githubWorkflowCheck" :: "check" :: (if (version == scala213) Nil else List("scripted"))
16+
}.mkString(";")
3017
)
3118

3219
addCommandAlias(
33-
"mdocCheck",
20+
"check",
3421
List(
35-
"""set docs / mdocExtraArguments += "--check"""",
36-
"docs / mdoc"
37-
).mkString("; ")
22+
"scalafmtCheckAll",
23+
"scalastyle",
24+
"versionPolicyCheck",
25+
"docs/mdoc --check",
26+
"evicted",
27+
"undeclaredCompileDependenciesTest",
28+
"unusedCompileDependenciesTest",
29+
"dependencyCheckAggregate",
30+
"test"
31+
).mkString(";")
3832
)
3933

4034
val isScala213 = settingKey[Boolean]("Checks if the current Scala version is 2.13")
@@ -58,19 +52,7 @@ inThisBuild(
5852
organization := "nz.co.bottech",
5953
organizationName := "BotTech",
6054
githubWorkflowBuild := List(
61-
WorkflowStep.Sbt(List("scalafmtCheckAll", "scalastyle"), name = Some("Check formatting and style")),
62-
WorkflowStep.Sbt(List("versionPolicyCheck"), name = Some("Check version adheres to the policy")),
63-
WorkflowStep.Sbt(List("mdocCheck"), name = Some("Check documentation has been generated")),
64-
WorkflowStep.Sbt(
65-
List(
66-
"evicted",
67-
"undeclaredCompileDependenciesTest",
68-
"unusedCompileDependenciesTest",
69-
"dependencyCheckAggregate"
70-
),
71-
name = Some("Check dependencies")
72-
),
73-
WorkflowStep.Sbt(List("test"), name = Some("Build and test")),
55+
WorkflowStep.Sbt(List("check"), name = Some("Build, test and check libraries")),
7456
WorkflowStep.Sbt(
7557
List("scripted"),
7658
name = Some("Build and test sbt plugin"),
@@ -126,10 +108,8 @@ val metaProjectSettings = List(
126108
publish / skip := true
127109
)
128110

129-
val libraryProjectSettings = commonProjectSettings
130-
131111
lazy val root = (project in file("."))
132-
.aggregate(cli, core, docs, sbtProject)
112+
.aggregate(cli, core, docs, example, sbtProject)
133113
.settings(metaProjectSettings)
134114
.settings(
135115
crossScalaVersions := supportedScalaVersions,
@@ -141,7 +121,7 @@ lazy val root = (project in file("."))
141121
)
142122

143123
lazy val core = project
144-
.settings(libraryProjectSettings)
124+
.settings(commonProjectSettings)
145125
.settings(
146126
libraryDependencies ++= collectionsCompatibilityDependency.value,
147127
libraryDependencies ++= List(
@@ -154,7 +134,7 @@ lazy val core = project
154134
),
155135
name := s"${(LocalRootProject / name).value}",
156136
semanticdbEnabled := true,
157-
semanticdbVersion := "4.4.10",
137+
semanticdbVersion := sdbVersion,
158138
testFrameworks += new TestFramework("utest.runner.Framework"),
159139
Test / managedSourceDirectories += (Test / semanticdbTargetRoot).value,
160140
Test / fullClasspath += (Test / semanticdbTargetRoot).value
@@ -163,7 +143,7 @@ lazy val core = project
163143
lazy val cli = project
164144
.dependsOn(core)
165145
.enablePlugins(BuildInfoPlugin)
166-
.settings(libraryProjectSettings)
146+
.settings(commonProjectSettings)
167147
.settings(
168148
buildInfoKeys := Seq[BuildInfoKey](version),
169149
buildInfoPackage := s"${organization.value}.${(LocalRootProject / name).value}",
@@ -183,10 +163,9 @@ lazy val sbtProject = (project in file("sbt"))
183163
.settings(commonProjectSettings)
184164
.settings(
185165
libraryDependencies ++= {
186-
// Don't add dependencies when the rest of the build is cross building with Scala 2.13
187-
// otherwise it will cause a whole lot of resolution failures.
188-
if ((core / isScala213).value) Nil
189-
else
166+
// Only add dependencies when the build is building with a Scala version that is
167+
// sbt compatible otherwise it will cause a whole lot of resolution failures.
168+
if (spspCanBuild.value)
190169
collectionsCompatibilityDependency.value ++ List(
191170
"org.scala-sbt" %% "collections" % sbtVersion.value,
192171
"org.scala-sbt" %% "command" % sbtVersion.value,
@@ -202,6 +181,7 @@ lazy val sbtProject = (project in file("sbt"))
202181
"org.scala-sbt" %% "util-logging" % sbtVersion.value,
203182
"org.scala-sbt" %% "util-position" % sbtVersion.value
204183
)
184+
else Nil
205185
},
206186
name := s"sbt-${(LocalRootProject / name).value}",
207187
scriptedBufferLog := false,
@@ -230,6 +210,15 @@ lazy val docs = (project in file("doc-templates"))
230210
unusedCompileDependenciesFilter -= moduleFilter("org.scalameta", "mdoc*")
231211
)
232212

213+
lazy val example = project
214+
.settings(commonProjectSettings)
215+
.settings(
216+
semanticdbEnabled := true,
217+
semanticdbIncludeInJar := true,
218+
semanticdbVersion := sdbVersion,
219+
versionPolicyFirstVersion := Some("0.1.13"),
220+
)
221+
233222
def isScala213Setting: Def.Initialize[Boolean] = Def.setting {
234223
CrossVersion.partialVersion(scalaVersion.value) match {
235224
case Some((2, n)) if n == 13 => true

docs/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Scala2PlantUML
22

3-
[![Continuous Integration](https://github.com/BotTech/scala2plantuml/actions/workflows/ci.yml/badge.svg)](https://github.com/BotTech/scala2plantuml/actions/workflows/ci.yml)
4-
![Scala2PlantUML Version](https://img.shields.io/maven-central/v/nz.co.bottech/scala2plantuml_2.13?label=Scala2PlantUML)
3+
[![Build badge](https://img.shields.io/github/workflow/status/BotTech/scala2plantuml/Continuous%20Integration/main)](https://github.com/BotTech/scala2plantuml/actions/workflows/ci.yml)
4+
[![Maven-Central badge](https://img.shields.io/maven-central/v/nz.co.bottech/scala2plantuml_2.13)](https://search.maven.org/search?q=g:nz.co.bottech%20a:*scala2plantuml*)
5+
[![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org)
56

67
Scala2PlantUML generates [PlantUML] diagrams from Scala code.
78

@@ -52,6 +53,7 @@ cs install --channel https://git.io/Jqv1i scala2plantuml
5253
### Usage
5354

5455
```text
56+
> scala2plantuml --help
5557
Scala2PlantUML version @VERSION@
5658
Usage: scala2plantuml [options] symbol
5759
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package nz.co.bottech.scala2plantuml.example
2+
3+
class A extends B {
4+
override def b: C = C(this)
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package nz.co.bottech.scala2plantuml.example
2+
3+
trait B {
4+
5+
def b: C
6+
}
7+
8+
object B {
9+
10+
val Const: String = "X"
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package nz.co.bottech.scala2plantuml.example
2+
3+
final case class C(value: A)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package nz.co.bottech.scala2plantuml.example
2+
3+
object Main extends App {
4+
5+
{
6+
val _ = new A
7+
}
8+
}

project/ConditionalKeys.scala

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import sbt.Keys.skip
2+
import sbt.{Def, InputKey, InputTask, Task, TaskKey}
3+
4+
object ConditionalKeys {
5+
6+
def settingDefaultIfSetting[A, B](
7+
setting: Def.Initialize[A],
8+
condition: Def.Initialize[B],
9+
default: => A
10+
)(
11+
p: B => Boolean
12+
): Def.Initialize[A] = Def.setting {
13+
if (p(condition.value)) {
14+
default
15+
} else {
16+
setting.value
17+
}
18+
}
19+
20+
def taskDefaultIfSkipped[A](task: TaskKey[A], default: => A): Def.Initialize[Task[A]] =
21+
taskDefaultIfTask(task, task / skip, default)(identity)
22+
23+
def taskDefaultIfSetting[A, B](
24+
task: Def.Initialize[Task[A]],
25+
condition: Def.Initialize[B],
26+
default: => A
27+
)(
28+
p: B => Boolean
29+
): Def.Initialize[Task[A]] = Def.taskIf {
30+
if (p(condition.value)) {
31+
default
32+
} else {
33+
task.value
34+
}
35+
}
36+
37+
def taskDefaultIfTask[A, B](
38+
task: Def.Initialize[Task[A]],
39+
condition: Def.Initialize[Task[B]],
40+
default: => A
41+
)(
42+
p: B => Boolean
43+
): Def.Initialize[Task[A]] = Def.taskIf {
44+
if (p(condition.value)) {
45+
default
46+
} else {
47+
task.value
48+
}
49+
}
50+
51+
def inputDefaultIfSkipped[A](input: InputKey[A], default: => A): Def.Initialize[InputTask[A]] =
52+
inputDefaultIfTask(input, input / skip, default)(identity)
53+
54+
def inputDefaultIfTask[A, B](
55+
input: InputKey[A],
56+
condition: Def.Initialize[Task[B]],
57+
default: => A
58+
)(
59+
p: B => Boolean
60+
): Def.Initialize[InputTask[A]] = Def.inputTaskDyn {
61+
val task = input.parsed
62+
Def.taskIf {
63+
if (p(condition.value)) {
64+
default
65+
} else {
66+
task.value
67+
}
68+
}
69+
}
70+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import ConditionalKeys._
2+
import com.typesafe.tools.mima.plugin.MimaKeys.mimaPreviousArtifacts
3+
import explicitdeps.ExplicitDepsPlugin
4+
import explicitdeps.ExplicitDepsPlugin.autoImport._
5+
import sbt.Keys._
6+
import sbt.ScriptedPlugin.autoImport.scripted
7+
import sbt._
8+
import sbt.plugins.SbtPlugin
9+
import sbtversionpolicy.SbtVersionPolicyMima
10+
11+
// This is all the crazy hacks to get cross compiling working with an sub-project that is an sbt plugin.
12+
object SbtPluginSubProjectPlugin extends AutoPlugin {
13+
14+
override def trigger: PluginTrigger = allRequirements
15+
override def requires: Plugins = SbtPlugin && SbtVersionPolicyMima && ExplicitDepsPlugin
16+
17+
object autoImport {
18+
val spspCanBuild = settingKey[Boolean]("Checks if the project dependencies are using a compatible Scala version.")
19+
}
20+
21+
import autoImport._
22+
23+
override def projectSettings: Seq[Def.Setting[_]] =
24+
List(
25+
crossScalaVersions := Nil,
26+
// Remove all project dependencies for Scala 2.13 as they will not resolve when cross building.
27+
projectDependencies := taskDefaultIfSkipped(projectDependencies, Nil).value,
28+
scripted := inputDefaultIfSkipped(scripted, ()).evaluated,
29+
spspCanBuild := canBuildSetting.value,
30+
// We can't skip this as it has to run at least once or sbt complains.
31+
update / skip := false,
32+
// Skip everything else otherwise it will just fail.
33+
skip := !spspCanBuild.value,
34+
undeclaredCompileDependenciesFilter -= moduleFilter(),
35+
mimaPreviousArtifacts := defaultIfCannotBuild(mimaPreviousArtifacts, Set.empty[ModuleID]).value
36+
)
37+
38+
def defaultIfCannotBuild[A](setting: Def.Initialize[A], default: => A): Def.Initialize[A] =
39+
settingDefaultIfSetting(setting, spspCanBuild, default)(!_)
40+
41+
private def canBuildSetting = Def.setting {
42+
if (!isScala212(scalaVersion.value))
43+
throw new IllegalStateException(
44+
"sbt project must use Scala 2.12. Check that you have not forced the version with '+'."
45+
)
46+
val versions =
47+
scalaVersion.all(ScopeFilter(inDependencies(ThisProject, transitive = true, includeRoot = false))).value
48+
versions.forall(isScala212)
49+
}
50+
51+
private def isScala212(version: String) =
52+
CrossVersion.partialVersion(version) match {
53+
case Some((2, n)) if n == 12 => true
54+
case _ => false
55+
}
56+
}

0 commit comments

Comments
 (0)