forked from enso-org/enso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStdBits.scala
65 lines (61 loc) · 2.39 KB
/
StdBits.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sbt.Keys._
import sbt._
import sbt.io.IO
import sbt.librarymanagement.{ConfigurationFilter, DependencyFilter}
object StdBits {
/** Discovers dependencies of a project and copies them into the destination
* directory.
*
* @param destination location where to put the dependencies
* @param baseJarName name of the base generated JAR (if any); 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: Option[String],
ignoreScalaLibrary: Boolean
): Def.Initialize[Task[Unit]] =
Def.task {
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.toSeq
for (existing <- IO.listFiles(destination)) {
if (!expectedFileNames.contains(existing.getName)) {
log.info(
s"Removing outdated std-bits dependency ${existing.getName}."
)
IO.delete(existing)
}
}
for (changed <- report.modified -- report.removed) {
log.info(
s"Updating changed std-bits dependency ${changed.getName}."
)
IO.copyFile(changed, destination / changed.getName)
}
for (file <- report.unmodified) {
val dest = destination / file.getName
if (!dest.exists()) {
log.info(s"Adding missing std-bits dependency ${file.getName}.")
IO.copyFile(file, dest)
}
}
}
}
}