Skip to content

Commit

Permalink
Collect all the module trees in the plugin and query that from direct…
Browse files Browse the repository at this point in the history
…ive (#10)

One downside is that it now requires to populate `paradoxDependenciesModules` on the use side. But on the other hand, the access to the dependency tree is now done without touching the state directly.

Fixes #9
  • Loading branch information
2m authored and ennru committed Jan 15, 2019
1 parent 322b90c commit d693603
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ addSbtPlugin("com.lightbend.paradox" % "sbt-paradox-dependencies" % <latest>)
```

Use the directive in a Paradox markdown file and specify the sbt project id.

```
@@dependencies { projectId="core" }
```

Any project from the build root project aggregates can be specified. If the project is not among the aggregates, then it needs
to be added to the `paradoxDependenciesProjects` setting value.

## License

The license is Apache 2.0, see LICENSE.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,31 @@ object ParadoxDependenciesPlugin extends AutoPlugin {

override def projectSettings: Seq[Setting[_]] = dependenciesSettings(Compile)

def dependenciesGlobalSettings: Seq[Setting[_]] = Seq(
def dependenciesZeroSettings: Seq[Setting[_]] = Seq(
paradoxDependenciesModuleTrees := Def.taskDyn {
val projectsToFilter = paradoxDependenciesProjects.?.value
.map(inProjects)
.getOrElse {
inAggregates(LocalRootProject, includeRoot = true)
}

val filter: ScopeFilter = ScopeFilter(projectsToFilter, inConfigurations(Compile))

val projectIdWithTree = Def.task {
(thisProject.value.id, ModuleTree(DependencyGraphKeys.moduleGraphSbt.value))
}

projectIdWithTree.all(filter).map(_.toMap)
}.value,
paradoxDirectives ++= Def.taskDyn {
Def.task {
val s = state.value
val trees = paradoxDependenciesModuleTrees.value
Seq(
{ _: Writer.Context
new DependenciesDirective(projectId => {
Project.runTask(LocalProject(projectId) / Compile / DependencyGraphKeys.moduleGraphSbt, s) match {
case Some((_, Value(deps))) => ModuleTree(deps)
case _ => throw new Error(s"Could not retrieve dependency information for projectId [$projectId]")
trees.get(projectId) match {
case Some(deps) => deps
case _ => throw new Error(s"Could not retrieve dependency information for project [$projectId]")
}
})
}
Expand All @@ -52,7 +67,7 @@ object ParadoxDependenciesPlugin extends AutoPlugin {
)

def dependenciesSettings(config: Configuration): Seq[Setting[_]] =
dependenciesGlobalSettings ++ inConfig(config)(
dependenciesZeroSettings ++ inConfig(config)(
Seq(
// scoped settings here
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@

package com.lightbend.paradox.dependencies

trait ParadoxDependenciesPluginKeys {}
import net.virtualvoid.sbt.graph.ModuleTree

import sbt._

trait ParadoxDependenciesPluginKeys {
val paradoxDependenciesProjects = settingKey[Seq[ProjectReference]]("Projects to get the dependency information for")
val paradoxDependenciesModuleTrees = taskKey[Map[String, ModuleTree]]("Retrieved module trees")
}
13 changes: 5 additions & 8 deletions src/sbt-test/dependencies/multi-module/build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
enablePlugins(ParadoxPlugin)
paradoxTheme := None

libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.17"

lazy val projectA = project
.settings(
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.17"
Expand All @@ -16,7 +11,9 @@ lazy val projectB = Project("projectBee", file("bee"))
libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.25"
)

lazy val multiModule = project
.aggregate(
projectB
lazy val multiModule = (project in file("."))
.settings(
paradoxTheme := None
)
.enablePlugins(ParadoxPlugin)
.aggregate(projectB)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$page.content$
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module has the following dependencies:

@@dependencies { module="module1" }
8 changes: 7 additions & 1 deletion src/sbt-test/dependencies/multi-module/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# expect to fail, because projectA is not part of the root aggregate
-> paradox

> set paradoxDependenciesProjects := Seq(projectA, projectB)

# now plugin knows about all projects and is able to generate dependency info for all
> paradox

$ must-mirror target/paradox/site/main/index.html expected/index.html
$ must-mirror target/paradox/site/main/index.html expected/index.html

0 comments on commit d693603

Please sign in to comment.