Skip to content

Instantly share code, notes, and snippets.

@quintona
Created March 21, 2014 05:54
Show Gist options
  • Save quintona/9680329 to your computer and use it in GitHub Desktop.
Save quintona/9680329 to your computer and use it in GitHub Desktop.
SBT Build plugin for Hadoop legacy jar format
object build extends Build {
val maestroJar = TaskKey[File]("maestro-jar", "Creates a packaged jar that works for maestro")
def allFiles(base: File): Seq[File] = {
val finder: PathFinder = PathFinder(base).***
finder.get
}
val maestroJarSettings: Seq[Project.Setting[_]] = inTask(maestroJar)(Seq(
artifactPath <<= artifactPathSetting(artifact),
cacheDirectory <<= cacheDirectory / maestroJar.key.label
)) ++ Seq(
publishArtifact in maestroJar <<= publishMavenStyle,
mainClass in maestroJar <<= mainClass in run in Compile,
packageOptions in maestroJar <++= (mainClass in maestroJar).map {
case Some(mainClass) => Seq(ManifestAttributes((MAIN_CLASS, mainClass)))
case _ => Seq()
},
mappings in maestroJar <<= (products in Compile, dependencyClasspath in Runtime).map {(products, classpath) =>
println(products)
val thisArtifactMapping: Seq[(File, String)] = products.map(f => {
val topLevel = List.fromArray(f.list()).map(t => new File(f, t))
val children = topLevel.flatMap(x => allFiles(x))
children.map(c => (c, Path.relativizeFile(f, c)))
.filter{_ match {
case (_, None) => false
case (_,Some(_)) => true
}
}
.map{x => (x._1,x._2.getOrElse(f).toString)}
}).flatten
println(thisArtifactMapping)
val deps: Seq[(File, String)] = {
val allDeps = Build.data(classpath).map(f => (f, (file("lib") / f.name).getPath))
allDeps.filterNot(_._1 == artifact)
}
thisArtifactMapping ++ deps
},
maestroJar <<= (mappings in maestroJar, artifactPath in maestroJar, packageOptions in maestroJar, cacheDirectory in maestroJar, streams) map {
(mappings, output, packOpts, cacheDir, s) =>
val packageConf = new Package.Configuration(mappings, output, packOpts)
Package(packageConf, cacheDir, s.log)
output
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment