Skip to content

Commit

Permalink
Add the ability to archive extra files with netLogoZipExtras
Browse files Browse the repository at this point in the history
  • Loading branch information
mrerrormessage committed Aug 25, 2015
1 parent 75b059e commit c035e0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ organization := "org.nlogo"

scalaVersion := "2.10.4"

version := "2.1_5.3.x"
version := "2.2_5.3.x"
36 changes: 19 additions & 17 deletions src/main/scala/org/nlogo/build/NetLogoExtension.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object NetLogoExtension extends AutoPlugin {
val netLogoExtName = settingKey[String]("extension-name")
val netLogoClassManager = settingKey[String]("extension-class-manager")
val netLogoZipSources = settingKey[Boolean]("extension-zip-sources")
val netLogoZipExtras = taskKey[Seq[(File, String)]]("extension-zip-extras")
}

import autoImport._
Expand All @@ -22,6 +23,15 @@ object NetLogoExtension extends AutoPlugin {

netLogoZipSources := true,

netLogoZipExtras := {
(dependencyClasspath in Runtime).value.files
.filter(path =>
path.getName.endsWith(".jar") &&
!path.getName.startsWith("scala-library") &&
!path.getName.startsWith("NetLogo"))
.map(path => (path, path.getName))
},

artifactName := ((_, _, _) => s"${name.value}.jar"),

packageOptions +=
Expand All @@ -37,25 +47,17 @@ object NetLogoExtension extends AutoPlugin {
val jar = (packageBin in Compile).value
val name = netLogoExtName.value

val libraryJarPaths =
(dependencyClasspath in Runtime).value.files.filter (path =>
path.getName.endsWith(".jar") &&
!path.getName.startsWith("scala-library") &&
!path.getName.startsWith("NetLogo"))

IO.copyFile(jar, baseDir / s"$name.jar")
libraryJarPaths foreach (path => IO.copyFile(path, baseDir / path.getName))

if(Process("git diff --quiet --exit-code HEAD").! == 0) {
if (netLogoZipSources.value) {
Process(s"git archive -o $name.zip --prefix=$name/ HEAD").!!
val sourcesToZip: Seq[(File, String)] =
if (netLogoZipSources.value) {
val allFiles = Process(s"git ls-files").lines_!.filterNot(_ == ".gitignore")
allFiles.map(new File(_)) zip allFiles
} else
Seq()
val zipMap = (sourcesToZip ++ netLogoZipExtras.value :+ (jar -> s"$name.jar")).map {
case (file, zipPath) => (file, s"$name/$zipPath")
}
val zipExtras = libraryJarPaths.map(_.getName) :+ s"$name.jar"
zipExtras foreach (extra => IO.copyFile(baseDir / extra, baseDir / name / extra))
val extrasStr = zipExtras.map(name + "/" + _).mkString(" ")
val cmd = s"zip -r $name.zip ${extrasStr}"
Process(cmd).!!
IO.delete(baseDir / name)
IO.zip(zipMap, baseDir / s"$name.zip")
}
else {
streams.value.log.warn("working tree not clean; no zip archive made")
Expand Down

0 comments on commit c035e0c

Please sign in to comment.