Skip to content

Commit

Permalink
Merge pull request #8 from ennru/settings-scopes
Browse files Browse the repository at this point in the history
Put `projectInfoVersion` in Global scope
  • Loading branch information
2m authored Mar 5, 2019
2 parents f6fd9b8 + d7ec0e8 commit 5482098
Showing 1 changed file with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,54 @@ object ParadoxProjectInfoPlugin extends AutoPlugin {

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

def projectInfoGlobalSettings: Seq[Setting[_]] = Seq(
override def globalSettings: Seq[Setting[_]] = Seq(
projectInfoVersion := version.value,
paradoxDirectives ++= Def.taskDyn {
Def.task {
val s = state.value
Seq(
{
_: Writer.Context
val f = new File((LocalRootProject / baseDirectory).value, "project/project-info.conf")
if (f.exists()) {
val extracted = Project.extract(s)
val rootVersion = extracted.get(projectInfoVersion)
val config = ConfigFactory
.parseFile(f)
// inject into config before resolving
.withValue("project-info.version", ConfigValueFactory.fromAnyRef(rootVersion))
.resolve()
.getConfig("project-info")
val sbtDetails: String => SbtValues = projectId => {
val project = LocalProject(projectId)
val projectName = try { extracted.get(project / name) } catch {
case e: Exception =>
throw new RuntimeException(
s"couldn't read sbt setting `$projectId / name`, does the projectId exist?")
}
SbtValues(
projectName,
extracted.get(project / version),
extracted.get(project / organization),
extracted.get(project / homepage),
extracted.get(project / scmInfo),
extracted.get(project / licenses).toList,
extracted.get(project / crossScalaVersions).toList,
)
}
new ProjectInfoDirective(config, sbtDetails)
} else {
throw new Error(s"Could not retrieve project-info from ${f.absolutePath}")
}
}
)
}
}.value
)

def projectInfoSettings(config: Configuration): Seq[Setting[_]] =
projectInfoGlobalSettings ++ inConfig(config)(
Seq(
paradoxDirectives ++= Def.taskDyn {
Def.task {
val s = state.value
Seq(
{
_: Writer.Context
val f = new File((LocalRootProject / baseDirectory).value, "project/project-info.conf")
if (f.exists()) {
val extracted = Project.extract(s)
val rootVersion = extracted.get(projectInfoVersion)
val config = ConfigFactory
.parseFile(f)
// inject into config before resolving
.withValue("project-info.version", ConfigValueFactory.fromAnyRef(rootVersion))
.resolve()
.getConfig("project-info")
val sbtDetails: String => SbtValues = projectId => {
val project = LocalProject(projectId)
val projectName = try { extracted.get(project / name) } catch {
case e: Exception =>
throw new RuntimeException(
s"couldn't read sbt setting `$projectId / name`, does the projectId exist?")
}
SbtValues(
projectName,
extracted.get(project / version),
extracted.get(project / organization),
extracted.get(project / homepage),
extracted.get(project / scmInfo),
extracted.get(project / licenses).toList,
extracted.get(project / crossScalaVersions).toList,
)
}
new ProjectInfoDirective(config, sbtDetails)
} else {
throw new Error(s"Could not retrieve project-info from ${f.absolutePath}")
}
}
)
}
}.value
) ++ inConfig(config)(
Seq(
// scoped settings here
))
Expand Down

0 comments on commit 5482098

Please sign in to comment.