Skip to content

Commit 60df9f3

Browse files
committed
Add ignoredConfigs in SubmitInput
1 parent 2b64cc2 commit 60df9f3

File tree

6 files changed

+90
-9
lines changed

6 files changed

+90
-9
lines changed

sbt-plugin/src/main/contraband/input.contra

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ type SubmitInput {
1616
## The name of module is composed of the name of the project and its binary version.
1717
## Example: foo_2.13
1818
ignoredModules: [String]
19+
20+
## A set of sbt configurations to ignore.
21+
## Examples:
22+
## - "test" to ignore the test dependencies
23+
## - "scala-doc-tool" to ignore the scaladoc dependencies
24+
## - "scala-tool" to ignore the compiler dependencies
25+
ignoredConfigs: [String]
1926
}

sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,20 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
8888

8989
private def includeProject(projectRef: ProjectRef, state: State, logger: Logger): Boolean = {
9090
val ignoredModules = state.attributes(githubSubmitInputKey).ignoredModules
91-
val scalaVersion = state.setting(projectRef / Keys.artifactName / Keys.scalaVersion)
92-
val scalaBinaryVersion = state.setting(projectRef / Keys.artifactName / Keys.scalaBinaryVersion)
93-
val projectID = state.setting(projectRef / Keys.projectID)
94-
val moduleName = CrossVersion(scalaVersion, scalaBinaryVersion).apply(projectID).name
91+
val moduleName = getModuleName(projectRef, state)
9592
val ignored = ignoredModules.contains(moduleName)
9693
if (!ignored) logger.info(s"Including dependency graph of $moduleName")
9794
else logger.info(s"Excluding dependency graph of $moduleName")
9895
!ignored
9996
}
10097

98+
private def getModuleName(projectRef: ProjectRef, state: State): String = {
99+
val scalaVersion = state.setting(projectRef / Keys.artifactName / Keys.scalaVersion)
100+
val scalaBinaryVersion = state.setting(projectRef / Keys.artifactName / Keys.scalaBinaryVersion)
101+
val projectID = state.setting(projectRef / Keys.projectID)
102+
CrossVersion(scalaVersion, scalaBinaryVersion).apply(projectID).name
103+
}
104+
101105
private def manifestTask: Def.Initialize[Task[Option[Manifest]]] = Def.task {
102106
// updateFull is needed to have information about callers and reconstruct dependency tree
103107
val reportResult = Keys.updateFull.result.value
@@ -108,17 +112,26 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
108112
val allDirectDependencies = Keys.allDependencies.value
109113
val baseDirectory = Keys.baseDirectory.value
110114
val logger = Keys.streams.value.log
111-
val onResolveFailure = Keys.state.value.get(githubSubmitInputKey).flatMap(_.onResolveFailure)
115+
val input = Keys.state.value.get(githubSubmitInputKey)
116+
117+
val onResolveFailure = input.flatMap(_.onResolveFailure)
118+
val ignoredConfigs = input.toSeq.flatMap(_.ignoredConfigs).toSet
119+
val moduleName = crossVersion(projectID).name
112120

113121
def getReference(module: ModuleID): String =
114122
crossVersion(module)
115123
.withConfigurations(None)
116124
.withExtraAttributes(Map.empty)
117125
.toString
118126

127+
def includeConfig(config: ConfigRef): Boolean =
128+
if (ignoredConfigs.contains(config.name)) {
129+
logger.info(s"Excluding config ${config.name} of ${moduleName} from its dependency graph")
130+
false
131+
} else true
132+
119133
reportResult match {
120134
case Inc(cause) =>
121-
val moduleName = crossVersion(projectID).name
122135
val message = s"Failed to resolve the dependencies of $moduleName"
123136
onResolveFailure match {
124137
case Some(OnFailure.warning) =>
@@ -132,9 +145,9 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
132145
val alreadySeen = mutable.Set[String]()
133146
val moduleReports = mutable.Buffer[(ModuleReport, ConfigRef)]()
134147
val allDependencies = mutable.Buffer[(String, String)]()
135-
136148
for {
137149
configReport <- report.configurations
150+
if !ignoredConfigs.contains(configReport.configuration.name)
138151
moduleReport <- configReport.modules
139152
moduleRef = getReference(moduleReport.module)
140153
if !moduleReport.evicted && !alreadySeen.contains(moduleRef)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import ch.epfl.scala.githubapi.DependencyRelationship
2+
import ch.epfl.scala.githubapi.DependencyScope
3+
import ch.epfl.scala.githubapi.Manifest
4+
import ch.epfl.scala.SubmitInput
5+
import sjsonnew.shaded.scalajson.ast.unsafe.JString
6+
7+
val checkScaladoc = taskKey[Unit]("Check scaladoc_3 is in the manifest ")
8+
val ignoreScaladoc = taskKey[StateTransform]("Ignore the scala-doc-tool in the submit input")
9+
val checkIgnoreScaladoc = taskKey[Unit]("Check scaladoc_3 is absent in the manifest")
10+
11+
inThisBuild(
12+
Seq(
13+
organization := "ch.epfl.scala",
14+
version := "1.2.0-SNAPSHOT",
15+
scalaVersion := "3.2.1"
16+
)
17+
)
18+
19+
Global / ignoreScaladoc := {
20+
val input = SubmitInput(None, Vector.empty, ignoredConfigs = Vector("scala-doc-tool"))
21+
StateTransform(state => state.put(githubSubmitInputKey, input))
22+
}
23+
24+
lazy val p1 = project
25+
.in(file("p1"))
26+
.settings(
27+
checkScaladoc := {
28+
val manifest = githubDependencyManifest.value.get
29+
checkDependency(manifest, "org.scala-lang:scaladoc_3:3.2.1")(
30+
expectedRelationship = DependencyRelationship.direct,
31+
expectedScope = DependencyScope.development,
32+
expectedConfig = "scala-doc-tool"
33+
)
34+
},
35+
checkIgnoreScaladoc := {
36+
val manifest = githubDependencyManifest.value.get
37+
val suspicious = manifest.resolved.keys.filter(dep => dep.contains("scaladoc_3"))
38+
assert(suspicious.isEmpty, s"The manifest should not contain scaladoc_3, found ${suspicious.mkString(", ")}")
39+
}
40+
)
41+
42+
def checkDependency(manifest: Manifest, name: String)(
43+
expectedRelationship: DependencyRelationship = DependencyRelationship.direct,
44+
expectedScope: DependencyScope = DependencyScope.runtime,
45+
expectedConfig: String = "compile",
46+
expectedDeps: Seq[String] = Seq.empty
47+
): Unit = {
48+
val node = manifest.resolved(name)
49+
assert(node.package_url.startsWith("pkg:maven/"), s"Wrong package_url for node $name: ${node.package_url}")
50+
assert(node.relationship.contains(expectedRelationship), s"Wrong relationship for node $name: ${node.relationship}")
51+
assert(node.scope.contains(expectedScope), s"Wrong scope for node $name: ${node.scope}")
52+
val configurations = node.metadata.get("config").collect { case JString(c) => c }
53+
assert(configurations.contains(expectedConfig), s"Wrong config in metadata for node $name: $configurations")
54+
expectedDeps.foreach(d => assert(node.dependencies.contains(d), s"missing dependency $d in node $name"))
55+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val pluginVersion = sys.props("plugin.version")
2+
3+
addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-submission" % pluginVersion)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> p1 / checkScaladoc
2+
> Global / ignoreScaladoc
3+
> p1 / checkIgnoreScaladoc

sbt-plugin/src/test/scala/ch/epfl/scala/JsonProtocolTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class JsonProtocolTests extends FunSuite {
3030
import ch.epfl.scala.JsonProtocol._
3131
val raw = Parser.parseUnsafe("{}")
3232
val obtained = Converter.fromJson[SubmitInput](raw).get
33-
val expected = SubmitInput(None, Vector.empty)
33+
val expected = SubmitInput(None, Vector.empty, Vector.empty)
3434
assertEquals(obtained, expected)
3535
}
3636

3737
test("decode input with onResolveFailure: warning") {
3838
import ch.epfl.scala.JsonProtocol._
3939
val raw = Parser.parseUnsafe("""{"onResolveFailure": "warning"}""")
4040
val obtained = Converter.fromJson[SubmitInput](raw).get
41-
val expected = SubmitInput(Some(OnFailure.warning), Vector.empty)
41+
val expected = SubmitInput(Some(OnFailure.warning), Vector.empty, Vector.empty)
4242
assertEquals(obtained, expected)
4343
}
4444
}

0 commit comments

Comments
 (0)