Created
April 13, 2012 14:47
-
-
Save rkuhn/2377391 to your computer and use it in GitHub Desktop.
Build.scala for merging reference.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
import Keys._ | |
import classpath.ClasspathUtilities.isArchive | |
import java.io.FileOutputStream | |
import sbtassembly.Plugin._ | |
import AssemblyKeys._ | |
object B extends Build { | |
lazy val merge = TaskKey[File]("merge-reference", | |
"merge all reference.conf") | |
lazy val mergeSettings: Seq[Project.Setting[_]] = Seq( | |
merge <<= (fullClasspath in assembly) map { c => | |
// collect from all elements of the full classpath | |
val (libs, dirs) = | |
c map (_.data) partition (isArchive) | |
// goal is to simply concatenate files here | |
val dest = file("reference.conf") | |
val out = new FileOutputStream(dest) | |
val append = IO.transfer(_: File, out) | |
try { | |
// first collect from managed sources | |
(dirs * "reference.conf").get foreach append | |
// then from dependency jars by unzipping and | |
// collecting reference.conf if present | |
for (lib <- libs) { | |
IO withTemporaryDirectory { dir => | |
IO.unzip(lib, dir, "reference.conf") | |
(dir * "reference.conf").get foreach append | |
} | |
} | |
// return merged file location as task result | |
dest | |
} finally { | |
out.close() | |
} | |
}, | |
// get rid of the individual files from jars | |
excludedFiles in assembly <<= | |
(excludedFiles in assembly) { | |
(old) => (bases) => | |
old(bases) ++ (bases flatMap (base => | |
(base / "reference.conf").get)) | |
}, | |
// tell sbt-assembly to include our merged file | |
assembledMappings in assembly <<= | |
(assembledMappings in assembly, merge) map { | |
(old, merged) => (f) => | |
old(f) :+ (merged, "reference.conf") | |
} | |
) | |
lazy val project = Project("fail", file("."), | |
settings = Defaults.defaultSettings ++ | |
assemblySettings ++ mergeSettings) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolvers += Resolver.url("sbt-plugin-releases", | |
new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns) | |
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.4") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment