Created
January 9, 2013 20:35
-
-
Save mikemckibben/4496696 to your computer and use it in GitHub Desktop.
An example of how to write a task that copies project dependencies to a directory.
This file contains hidden or 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
TaskKey[Unit]("copy-plugin-dependencies") <<= (update) map { | |
(updateReport) => | |
updateReport.select(Set("compile", "runtime")) map { jar => | |
import java.util.jar.{JarFile, Manifest => JarManifest} | |
val jarFile = new JarFile(jar) | |
val jarAttributes = jarFile.getManifest().getMainAttributes() | |
val targetdir = file("plugins") | |
if (!targetdir.exists) targetdir.mkdir() | |
else if (!targetdir.isDirectory) error("%s is not a directory".format(targetdir)) | |
for (bundleSymName <- Option(jarAttributes.getValue("Bundle-SymbolicName")); | |
version <- Option(jarAttributes.getValue("Bundle-Version"))) | |
yield { (bundleSymName, version, jar, targetdir) } | |
} foreach { _ match { | |
case Some((bundleSymName, version, jar, targetdir)) => { | |
import java.nio.file.Files | |
Files.copy(jar.toPath, targetdir.toPath.resolve("%s_%s.jar".format(bundleSymName, version))) | |
} | |
case None => () | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment