Skip to content

Commit

Permalink
Restrict dependencies of delombok in its task scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry committed Jan 10, 2019
1 parent da70055 commit 49d156b
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions Delombok/src/main/scala/com/thoughtworks/sbt/Delombok.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,45 @@ object Delombok extends AutoPlugin {
override def projectSettings: Seq[Def.Setting[_]] =
Seq(Compile, Test).flatMap(
inConfig(_)(
Seq(
delombokDirectory := target.value / "delombok",
delombok := {
val classPathArgument = s"--classpath=${Path.makeString(dependencyClasspath.value.map(_.data))}"
val targetArgument = s"--target=${delombokDirectory.value.getPath}"
val sourceDirectoryArguments = (doc / sourceDirectories).value.map(_.getPath)
val sourceFileArguments = for {
sourceFile <- sources.value
if sourceFile.ext == "java" &&
(doc / sourceDirectories).value.forall(sourceFile.relativeTo(_).isEmpty)
} yield sourceFile.getPath

runner.value
.run(
"lombok.launch.Main",
dependencyClasspath.value.map(_.data),
Seq("delombok", "--nocopy", "--onlyChanged", classPathArgument, targetArgument) ++
sourceDirectoryArguments ++ sourceFileArguments,
(delombok / streams).value.log
)
.get

sources.value.view.collect {
case sourceFile if sourceFile.ext == "java" =>
val relativeJavaFile = (doc / sourceDirectories).value
.collectFirst(Function.unlift(IO.relativize(_, sourceFile)))
.getOrElse(sourceFile.getName)
sourceFile -> delombokDirectory.value / relativeJavaFile
}.toMap
}
inTask(delombok)(
Seq(
Defaults.TaskZero / delombokDirectory := target.value / "delombok",
Defaults.TaskZero / delombok := {
val classPathArgument = s"--classpath=${Path.makeString(dependencyClasspath.value.map(_.data))}"
val targetArgument = s"--target=${delombokDirectory.value.getPath}"
val sourceDirectoryArguments = sourceDirectories.value.map(_.getPath)
val sourceFileArguments = for {
sourceFile <- sources.value
if sourceFile.ext == "java" &&
sourceDirectories.value.forall(sourceFile.relativeTo(_).isEmpty)
} yield sourceFile.getPath

runner.value
.run(
"lombok.launch.Main",
dependencyClasspath.value.map(_.data),
Seq("delombok", "--nocopy", "--onlyChanged", classPathArgument, targetArgument) ++
sourceDirectoryArguments ++ sourceFileArguments,
streams.value.log
)
.get

sources.value.view.collect {
case sourceFile if sourceFile.ext == "java" =>
val relativeJavaFile = sourceDirectories.value
.collectFirst(Function.unlift(IO.relativize(_, sourceFile)))
.getOrElse(sourceFile.getName)
sourceFile -> delombokDirectory.value / relativeJavaFile
}.toMap
}
)
)
)
)

object autoImport {
val delombokDirectory = settingKey[File]("Directory to save delomboked files to")
val delombok = taskKey[Map[File, File]]("Run delombok")
val delombok = taskKey[Map[File, File]]("Run delombok and return translated file pairs")
}

}

0 comments on commit 49d156b

Please sign in to comment.