2009-09-09 05:13:30 +02:00
|
|
|
import sbt._
|
|
|
|
|
import java.io.File
|
|
|
|
|
|
|
|
|
|
trait ProguardLaunch extends ProguardProject
|
|
|
|
|
{
|
2010-06-16 02:38:18 +02:00
|
|
|
override def optimize = 2
|
2009-10-19 04:25:50 +02:00
|
|
|
override def basicOptions = super.basicOptions ++ Seq(keepJLine)
|
2010-02-10 00:55:11 +01:00
|
|
|
def outputJar = rootProject.outputPath / ("sbt-launch-" + version + ".jar")
|
2010-06-16 02:38:18 +02:00
|
|
|
override def keepFullClasses =
|
|
|
|
|
"xsbti.**" ::
|
|
|
|
|
"jline.**" ::
|
|
|
|
|
Nil
|
|
|
|
|
override def keepClasses =
|
2009-09-09 05:13:30 +02:00
|
|
|
"org.apache.ivy.plugins.resolver.URLResolver" ::
|
|
|
|
|
"org.apache.ivy.plugins.resolver.IBiblioResolver" ::
|
|
|
|
|
Nil
|
2010-06-16 02:38:18 +02:00
|
|
|
|
2009-09-09 05:13:30 +02:00
|
|
|
override def mapInJars(inJars: Seq[File]) =
|
|
|
|
|
{
|
|
|
|
|
val inputJar = jarPath.asFile.getAbsolutePath
|
2010-02-15 02:25:11 +01:00
|
|
|
val jlineJars = runClasspath.getFiles.filter(isJLineJar)
|
2009-09-09 05:13:30 +02:00
|
|
|
// pull out Ivy in order to exclude resources inside
|
2010-02-15 02:25:11 +01:00
|
|
|
val (ivyJars, notIvy) = inJars.filter(jar => !isJLineJar(jar)).partition(isIvyJar)
|
2010-06-16 02:38:18 +02:00
|
|
|
val (libraryJar, remaining) = notIvy.partition(isScalaJar)
|
|
|
|
|
|
|
|
|
|
val otherJars = remaining.filter(jar => !isJarX(jar, "scala-compiler"))
|
2009-09-09 05:13:30 +02:00
|
|
|
|
2010-02-15 02:25:11 +01:00
|
|
|
log.debug("proguard configuration:")
|
|
|
|
|
log.debug("\tJLline jar location: " + jlineJars.mkString(", "))
|
|
|
|
|
log.debug("\tIvy jar location: " + ivyJars.mkString(", "))
|
|
|
|
|
log.debug("\tOther jars:\n\t" + otherJars.mkString("\n\t"))
|
2009-10-18 04:40:02 +02:00
|
|
|
val excludeIvyResourcesString = excludeString(excludeIvyResources)
|
|
|
|
|
((withJar(ivyJars.toSeq, "Ivy") + excludeIvyResourcesString) ::
|
2010-06-16 02:38:18 +02:00
|
|
|
(withJar(jlineJars, "JLine") + jlineFilter ) ::
|
|
|
|
|
(withJar(libraryJar, "Scala library") + libraryFilter) ::
|
|
|
|
|
otherJars.map(jar => mkpath(jar) + generalFilter).toList) map { "-injars " + _ }
|
2009-09-09 05:13:30 +02:00
|
|
|
}
|
|
|
|
|
|
2009-10-18 04:40:02 +02:00
|
|
|
private def excludeString(s: List[String]) = s.map("!" + _).mkString("(",",",")")
|
|
|
|
|
private def excludeIvyResources =
|
|
|
|
|
"META-INF/**" ::
|
|
|
|
|
"fr/**" ::
|
|
|
|
|
"**/antlib.xml" ::
|
|
|
|
|
"**/*.png" ::
|
|
|
|
|
"org/apache/ivy/core/settings/ivyconf*.xml" ::
|
|
|
|
|
"org/apache/ivy/core/settings/ivysettings-*.xml" ::
|
|
|
|
|
"org/apache/ivy/plugins/resolver/packager/*" ::
|
|
|
|
|
"**/ivy_vfs.xml" ::
|
|
|
|
|
"org/apache/ivy/plugins/report/ivy-report-*" ::
|
|
|
|
|
Nil
|
|
|
|
|
|
2010-06-16 02:38:18 +02:00
|
|
|
private def libraryFilter = "(!META-INF/**,!*.properties,!scala/actors/**.!scala/util/parsing/*.class,!scala/xml/**.class,!scala/package$.class,**.class)"
|
|
|
|
|
private def jlineFilter = "(!META-INF/**)"
|
|
|
|
|
private def generalFilter = "(!META-INF/**,!*.properties)"
|
|
|
|
|
|
2010-02-10 00:55:11 +01:00
|
|
|
private def withJar[T](files: Iterable[File], name: String) = mkpath(files.toSeq.firstOption.getOrElse(error(name + " not present (try running update)")))
|
2009-09-09 05:13:30 +02:00
|
|
|
private def isJLineJar(file: File) = isJarX(file, "jline")
|
2010-02-10 00:55:11 +01:00
|
|
|
private def isIvyJar(file: File) = isJarX(file, "ivy")
|
2010-06-16 02:38:18 +02:00
|
|
|
private def isScalaJar(file: File) = isJarX(file, "scala-library")
|
2009-09-09 05:13:30 +02:00
|
|
|
private def isJarX(file: File, x: String) =
|
|
|
|
|
{
|
|
|
|
|
val name = file.getName
|
|
|
|
|
name.startsWith(x) && name.endsWith(".jar")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val keepJLine =
|
|
|
|
|
"""
|
|
|
|
|
|-keep public class jline.** {
|
|
|
|
|
| public protected *;
|
|
|
|
|
|}
|
|
|
|
|
|""".stripMargin
|
|
|
|
|
}
|