Created
January 4, 2011 14:09
-
-
Save weberste/764797 to your computer and use it in GitHub Desktop.
SBT task to create a distributable zip file
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
trait DistributableProject extends BasicScalaProject with MavenStyleScalaPaths { | |
// staging is currently done to make ensure the paths of the files within the resulting zip end up in the correct directory structure | |
def stagingDir = (outputPath ##) / (normalizedName + "-" + version) | |
def distributionZipName = normalizedName + "-dist-" + version + ".zip" | |
def distributionOutputPath = outputPath / distributionZipName | |
def libTargetDirectoryName = "lib" | |
def libPaths = Path.lazyPathFinder { | |
runClasspath.get.toList.filter(sbt.ClasspathUtilities.isArchive) | |
} +++ mainDependencies.scalaJars | |
// to ensure `libPaths` does not include source and doc jars | |
override def classpathFilter = super.classpathFilter -- "*-sources.jar" -- "*-javadoc.jar" | |
def nativeDirectoryName = "native" | |
def nativeTargetDirectoryName = "native" | |
def nativePaths = (info.projectPath ##) / nativeDirectoryName ** "*.dll" | |
def mainJarPath = (outputPath ##) / defaultJarName | |
def allPaths = mainJarPath +++ nativePaths +++ (stagingDir / libTargetDirectoryName ***) | |
override def manifestClassPath = { | |
val manifestString = libPaths.get.map { | |
libTargetDirectoryName + File.separator + _.name | |
} | |
log.info("manifestString: " + manifestString) | |
Some(manifestString.mkString(" ")) | |
} | |
lazy val dist = distAction | |
def distAction = task { | |
FileUtilities.clean(distributionOutputPath, log) | |
// staging | |
log.debug("Included libs:" + libPaths.toString) | |
FileUtilities.copyFlat(libPaths.get, stagingDir / libTargetDirectoryName, log) | |
log.debug("Included native libs:" + nativePaths.toString) | |
FileUtilities.copy(nativePaths.get, stagingDir / nativeTargetDirectoryName, true, false, log) | |
log.debug("Included main jar:" + mainJarPath.toString) | |
FileUtilities.copy(mainJarPath.get, stagingDir, true, false, log) | |
log.debug("Creating output file:" + stagingDir.toString) | |
FileUtilities.zip(stagingDir.get, distributionOutputPath, true, log) | |
// cleanup | |
FileUtilities.clean(stagingDir, log) | |
None | |
} dependsOn (test, `package`) describedAs ("Creates a distributable archive.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment