-
Notifications
You must be signed in to change notification settings - Fork 0
/
assembly.sbt
93 lines (73 loc) · 4.01 KB
/
assembly.sbt
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.security.MessageDigest
import sbtassembly.{AssemblyUtils, MergeStrategy}
val takeGuavaFixMergeStrategy = new MergeStrategy {
val name = "takeGuavaFix"
private def filenames(tempDir: File, fs: Seq[File]): Seq[String] =
for(f <- fs) yield {
AssemblyUtils.sourceOfFileForMerge(tempDir, f) match {
case (path, base, subDirPath, false) => subDirPath
case (jar, base, subJarPath, true) => jar + ":" + subJarPath
}
}
private def sha1content(f: File): String = bytesToSha1String(IO.readBytes(f))
private def bytesToSha1String(bytes: Array[Byte]): String =
bytesToString(sha1.digest(bytes))
private def bytesToString(bytes: Seq[Byte]): String =
bytes map {"%02x".format(_)} mkString
private def sha1 = MessageDigest.getInstance("SHA-1")
def apply(tempDir: File, path: String, files: Seq[File]): Either[String, Seq[(File, String)]] = {
files.foreach(x => {
AssemblyUtils.sourceOfFileForMerge(tempDir, x) match {
case (_,_,_, false) => System.out.println("before filter: ", x.getPath)
case (jar, base, p, true) => System.out.println(s"before filter: jar=$jar base=$base p=$p x=${x.getPath}")
}
})
val filteredFiles = files.filter(f => {
AssemblyUtils.sourceOfFileForMerge(tempDir, f) match {
case (_,_,_, false) => true // local file, OK (trumps everything)
case (jar, base, p, true) => jar.getName.contains("guava-fix")
}
})
filteredFiles.foreach(x => {
AssemblyUtils.sourceOfFileForMerge(tempDir, x) match {
case (_,_,_, false) => System.out.println("after filter: ", x.getPath)
case (jar, base, p, true) => System.out.println(s"after filter: jar=$jar base=$base p=$p x=${x.getPath}")
}
})
if (filteredFiles.length == 1) {
Right(Seq(filteredFiles.head -> path)) // if "head" explodes, you DON'T have guava-fix or a local override.
} else {
val fingerprints = Set() ++ (filteredFiles map (sha1content))
if (fingerprints.size == 1) Right(Seq(filteredFiles.head -> path)) // good enough
else {
Left("even after filtering, found multiple files for same target path:" +
filenames(tempDir, filteredFiles).mkString("\n", "\n", ""))
}
}
}
}
assemblyMergeStrategy in assembly := {
case PathList(ps @ _*) if ps.last == "pom.properties" => MergeStrategy.rename
case PathList(ps @ _*) if ps.last == "pom.xml" => MergeStrategy.rename
case PathList("javax", "el", cl @_*) => MergeStrategy.rename
case PathList("com", "google", "common", "base", "Stopwatch$1.class") => takeGuavaFixMergeStrategy // first is aaaaa.acmecorp
case PathList("com", "google", "common", "base", "Stopwatch.class") => takeGuavaFixMergeStrategy
case PathList("com", "google", "common", "io", "Closeables.class") => takeGuavaFixMergeStrategy
case PathList("org", "apache", "hadoop", "yarn", "factories", "package-info.class") => MergeStrategy.first
case PathList("org", "apache", "hadoop", "yarn", "factory", "providers", "package-info.class") => MergeStrategy.first
case PathList("org", "apache", "hadoop", "yarn", "util", "package-info.class") => MergeStrategy.first
case PathList("core-default.xml") => MergeStrategy.first
case PathList("hdfs-default.xml") => MergeStrategy.first
case PathList("mapred-default.xml") => MergeStrategy.first
case PathList("org", "apache","hadoop", "hbase","mapred","TableInputFormatBase.class") => MergeStrategy.first
case PathList("org", "apache", "jasper", xs @ _*) => MergeStrategy.rename
case PathList("project.clj") => MergeStrategy.first
case PathList("javax", "servlet", xs @ _*) => MergeStrategy.first
case PathList(ps @ _*) if ps.last endsWith ".html" => MergeStrategy.first
case PathList("com", "esotericsoftware", "minlog", ps @ _*) => MergeStrategy.first
//case "application.conf" => MergeStrategy.concat
//case "unwanted.txt" => MergeStrategy.discard
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}