2020-10-09 17:19:58 +03:00
|
|
|
import sbt.Keys._
|
|
|
|
import sbt._
|
|
|
|
import sbt.io.IO
|
|
|
|
import sbt.librarymanagement.{ConfigurationFilter, DependencyFilter}
|
2020-10-02 19:17:21 +03:00
|
|
|
|
|
|
|
object StdBits {
|
2020-10-09 17:19:58 +03:00
|
|
|
|
2020-10-22 17:12:28 +03:00
|
|
|
/** Discovers dependencies of a project and copies them into the destination
|
2020-10-09 17:19:58 +03:00
|
|
|
* directory.
|
|
|
|
*
|
|
|
|
* @param destination location where to put the dependencies
|
|
|
|
* @param baseJarName name of the JAR generated by the `package` task;
|
|
|
|
* unexpected (old) files are removed, so this task needs
|
|
|
|
* to know this file's name to avoid removing it
|
|
|
|
* @param ignoreScalaLibrary whether to ignore Scala dependencies that are
|
|
|
|
* added by default be SBT and are not relevant in
|
|
|
|
* pure-Java projects
|
|
|
|
*/
|
|
|
|
def copyDependencies(
|
|
|
|
destination: File,
|
|
|
|
baseJarName: String,
|
|
|
|
ignoreScalaLibrary: Boolean
|
|
|
|
): Def.Initialize[Task[Unit]] =
|
2020-10-02 19:17:21 +03:00
|
|
|
Def.task {
|
2020-10-09 17:19:58 +03:00
|
|
|
val libraryUpdates = (Compile / update).value
|
|
|
|
val log = streams.value.log
|
|
|
|
|
|
|
|
val ignoredConfigurations: NameFilter =
|
|
|
|
if (ignoreScalaLibrary)
|
|
|
|
new ExactFilter(Configurations.ScalaTool.name)
|
|
|
|
else NothingFilter
|
|
|
|
val filter: ConfigurationFilter =
|
|
|
|
DependencyFilter.configurationFilter(-ignoredConfigurations)
|
|
|
|
val relevantFiles = libraryUpdates.select(filter)
|
|
|
|
|
|
|
|
val dependencyStore =
|
|
|
|
streams.value.cacheStoreFactory.make("std-bits-dependencies")
|
|
|
|
Tracked.diffInputs(dependencyStore, FileInfo.hash)(relevantFiles.toSet) {
|
|
|
|
report =>
|
|
|
|
val expectedFileNames = report.checked.map(_.getName) + baseJarName
|
|
|
|
for (existing <- IO.listFiles(destination)) {
|
|
|
|
if (!expectedFileNames.contains(existing.getName)) {
|
|
|
|
log.info(
|
|
|
|
s"Removing outdated std-bits dependency ${existing.getName}."
|
|
|
|
)
|
|
|
|
IO.delete(existing)
|
|
|
|
}
|
2020-10-02 19:17:21 +03:00
|
|
|
}
|
2020-10-09 17:19:58 +03:00
|
|
|
for (changed <- report.modified -- report.removed) {
|
|
|
|
log.info(
|
|
|
|
s"Updating changed std-bits dependency ${changed.getName}."
|
2020-10-02 19:17:21 +03:00
|
|
|
)
|
2020-10-09 17:19:58 +03:00
|
|
|
IO.copyFile(changed, destination / changed.getName)
|
|
|
|
}
|
2020-12-09 16:58:11 +03:00
|
|
|
for (file <- report.unmodified) {
|
2020-10-09 17:19:58 +03:00
|
|
|
val dest = destination / file.getName
|
|
|
|
if (!dest.exists()) {
|
|
|
|
log.info(s"Adding missing std-bits dependency ${file.getName}.")
|
|
|
|
IO.copyFile(file, dest)
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 19:17:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|