From a8f7c9dc3aa331b92d66aea3359c167656729954 Mon Sep 17 00:00:00 2001 From: Paul LaCrosse Date: Wed, 7 Nov 2012 12:03:24 -0500 Subject: [PATCH] upgrade to proguard 4.8 --- .gitignore | 5 + project/Build.scala | 124 ++++++++--------- src/main/scala/ProguardPlugin.scala | 203 ++++++++++++++-------------- 3 files changed, 169 insertions(+), 163 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eba48cd --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +target +project/target +project/project +lib_managed + diff --git a/project/Build.scala b/project/Build.scala index 43e1d5c..4cb6982 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1,62 +1,62 @@ -import sbt._ -import ScriptedPlugin._ -import Keys._ - -import scala.xml.{Elem, Node} - -object ProguardPlugin extends Build { - def pomPostProcessTask(node: Node) = node match { - case xml: Elem => - val children = Seq( - http://github.com/siasia/xsbt-web-plugin, - - - GPLv2 - http://www.gnu.org/licenses/gpl-2.0.html - repo - - , - - scm:git:git@github.com:siasia/xsbt-proguard-plugin.git - scm:git:git@github.com:siasia/xsbt-proguard-plugin.git - git@github.com:siasia/xsbt-proguard-plugin.git - , - - - siasia - Artyom Olshevskiy - siasiamail@gmail.com - - , - - org.sonatype.oss - oss-parent - 7 - - ) - xml.copy(child = xml.child ++ children) - } - def rootSettings: Seq[Setting[_]] = Seq( - scriptedBufferLog := false, - sbtPlugin := true, - projectID <<= (organization,moduleName,version,artifacts,crossPaths){ (org,module,version,as,crossEnabled) => - ModuleID(org, module, version).cross(crossEnabled).artifacts(as : _*) - }, - name := "xsbt-proguard-plugin", - organization := "com.github.siasia", - version <<= sbtVersion(_ + "-0.1.2"), - libraryDependencies += "net.sf.proguard" % "proguard-base" % "4.7", - scalacOptions += "-deprecation", - publishMavenStyle := true, - publishTo <<= (version) { - version: String => - val ossSonatype = "https://oss.sonatype.org/" - if (version.trim.endsWith("SNAPSHOT")) - Some("snapshots" at ossSonatype + "content/repositories/snapshots") - else None - }, - credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"), - pomIncludeRepository := ((_) => false), - pomPostProcess := (pomPostProcessTask _)) - lazy val root = Project("root", file(".")) settings(scriptedSettings ++ rootSettings :_*) -} +import sbt._ +import ScriptedPlugin._ +import Keys._ + +import scala.xml.{Elem, Node} + +object ProguardPlugin extends Build { + def pomPostProcessTask(node: Node) = node match { + case xml: Elem => + val children = Seq( + http://github.com/siasia/xsbt-web-plugin, + + + GPLv2 + http://www.gnu.org/licenses/gpl-2.0.html + repo + + , + + scm:git:git@github.com:siasia/xsbt-proguard-plugin.git + scm:git:git@github.com:siasia/xsbt-proguard-plugin.git + git@github.com:siasia/xsbt-proguard-plugin.git + , + + + siasia + Artyom Olshevskiy + siasiamail@gmail.com + + , + + org.sonatype.oss + oss-parent + 7 + + ) + xml.copy(child = xml.child ++ children) + } + def rootSettings: Seq[Setting[_]] = Seq( + scriptedBufferLog := false, + sbtPlugin := true, + projectID <<= (organization,moduleName,version,artifacts,crossPaths){ (org,module,version,as,crossEnabled) => + ModuleID(org, module, version).cross(crossEnabled).artifacts(as : _*) + }, + name := "xsbt-proguard-plugin", + organization := "com.github.siasia", + version <<= sbtVersion(_ + "-0.1.3"), + libraryDependencies += "net.sf.proguard" % "proguard-base" % "4.8", + scalacOptions += "-deprecation", + publishMavenStyle := true, + publishTo <<= (version) { + version: String => + val ossSonatype = "https://oss.sonatype.org/" + if (version.trim.endsWith("SNAPSHOT")) + Some("snapshots" at ossSonatype + "content/repositories/snapshots") + else None + }, + credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"), + pomIncludeRepository := ((_) => false), + pomPostProcess := (pomPostProcessTask _)) + lazy val root = Project("root", file(".")) settings(scriptedSettings ++ rootSettings :_*) +} diff --git a/src/main/scala/ProguardPlugin.scala b/src/main/scala/ProguardPlugin.scala index 052217d..9a0b744 100644 --- a/src/main/scala/ProguardPlugin.scala +++ b/src/main/scala/ProguardPlugin.scala @@ -1,101 +1,102 @@ -import sbt._ - -import Project.Initialize -import Keys._ -import CrossVersion.{binaryScalaVersion} -import proguard.{Configuration=>ProGuardConfiguration, ProGuard, ConfigurationParser} - -import java.io.File - -object ProguardPlugin extends Plugin { - def keepLimitedSerializability = """ - -keepclassmembers class * implements java.io.Serializable { - static long serialVersionUID; - private void writeObject(java.io.ObjectOutputStream); - private void readObject(java.io.ObjectInputStream); - java.lang.Object writeReplace(); - java.lang.Object readResolve(); - } - """ - - def keepSerializability = "-keep class * implements java.io.Serializable { *; }" - - def keepAllScala = "-keep class scala.** { *; }" - - def keepMain (name :String) = - "-keep public class " + name + " { static void main(java.lang.String[]); }" - - private def rtJarPath = { - val javaHome = new java.io.File(System.getProperty("java.home")) - val stdLocation = javaHome / "lib" / "rt.jar" - val osXLocation = new java.io.File(javaHome.getParent()) / "Classes"/ "classes.jar" - if (stdLocation.asFile.exists()) - stdLocation - else if (osXLocation.asFile.exists()) - osXLocation - else - throw new IllegalStateException("Unknown location for rt.jar") - } - val proguard = TaskKey[Unit]("proguard") - val minJarPath = SettingKey[File]("min-jar-path") - - private implicit def pathEscape(p: File) = new { - def escaped: String = '"' + Path.absolute(p).toString.replaceAll("\\s", "\\ ") + '"' - } - - val proguardDefaultArgs = SettingKey[Seq[String]]("proguard-default-args") - val proguardOptions = SettingKey[Seq[String]]("proguard-options") - val makeInJarFilter = SettingKey[String => String]("makeInJarFilter") - - private val proguardArgs = TaskKey[List[String]]("proguard-args") - val proguardInJars = TaskKey[Seq[File]]("proguard-in-jars") - val proguardInJarsTask = TaskKey[Seq[File]]("proguard-in-jars-task") - val proguardLibraryJars = TaskKey[Seq[File]]("proguard-library-jars") - - def proguardInJarsTaskImpl: Initialize[Task[Seq[File]]] = { - (dependencyClasspath in Compile, proguardInJars, proguardLibraryJars) map { - (dc, pij, plj) => - import Build.data - data(dc).filterNot(plj.contains) ++ pij - } - } - - def proguardArgsTask: Initialize[Task[List[String]]] = { - (proguardLibraryJars, proguardInJarsTask, artifactPath in (Compile, packageBin), makeInJarFilter, minJarPath, proguardDefaultArgs, proguardOptions, packageBin in Compile, streams) map { - (plj, pij, jp, mijf, mjp, pda, po, pb, s) => - val proguardInJarsArg = { - val inPaths = pij.foldLeft(Map.empty[String, File])((m, p) => m + (p.getName -> p)).values.iterator - "-injars" :: (List(jp.escaped).iterator ++ inPaths.map(p => p.escaped+"("+mijf(p.asFile.getName)+")")).mkString(File.pathSeparator) :: Nil - } - val proguardOutJarsArg = "-outjars" :: mjp.escaped :: Nil - val proguardLibJarsArg = { - val libPaths = plj.foldLeft(Map.empty[String, File])((m, p) => m + (p.getName -> p)).values.iterator - if (libPaths.hasNext) "-libraryjars" :: libPaths.map(_.escaped).mkString(File.pathSeparator) :: Nil else Nil - } - val args = proguardInJarsArg ::: proguardOutJarsArg ::: proguardLibJarsArg ::: pda.toList ::: po.toList - s.log.debug("Proguard args: " + args) - args - } - } - - def proguardTask(args: List[String], bd: File) { - val config = new ProGuardConfiguration - new ConfigurationParser(args.toArray[String], bd).parse(config) - new ProGuard(config).execute - } - - val proguardSettings = Seq( - minJarPath <<= (crossTarget, projectID, artifact, scalaVersion, artifactName) { (t, module, a, sv, toString) => - val scalaversion = ScalaVersion(sv, binaryScalaVersion(sv)) - t / toString(scalaversion, module.copy(revision = module.revision + ".min"), a) asFile - }, - proguardOptions := Nil, - makeInJarFilter := { (file) => "!META-INF/MANIFEST.MF" }, - proguardDefaultArgs := Seq("-dontwarn", "-dontoptimize", "-dontobfuscate"), - proguardLibraryJars := { (rtJarPath :PathFinder).get }, - proguardInJars <<= (scalaInstance) map { (si) => Seq(si.libraryJar) }, - proguardInJarsTask <<= proguardInJarsTaskImpl, - proguardArgs <<= proguardArgsTask, - proguard <<= (packageBin in Compile, proguardArgs in Compile, baseDirectory) map { (_, args, bd) => proguardTask(args, bd) } - ) -} +import sbt._ + +import Project.Initialize +import Keys._ +import CrossVersion.{binaryScalaVersion} +import proguard.{Configuration=>ProGuardConfiguration, ProGuard, ConfigurationParser} + +import java.io.File +import java.util.Properties + +object ProguardPlugin extends Plugin { + def keepLimitedSerializability = """ + -keepclassmembers class * implements java.io.Serializable { + static long serialVersionUID; + private void writeObject(java.io.ObjectOutputStream); + private void readObject(java.io.ObjectInputStream); + java.lang.Object writeReplace(); + java.lang.Object readResolve(); + } + """ + + def keepSerializability = "-keep class * implements java.io.Serializable { *; }" + + def keepAllScala = "-keep class scala.** { *; }" + + def keepMain (name :String) = + "-keep public class " + name + " { static void main(java.lang.String[]); }" + + private def rtJarPath = { + val javaHome = new java.io.File(System.getProperty("java.home")) + val stdLocation = javaHome / "lib" / "rt.jar" + val osXLocation = new java.io.File(javaHome.getParent()) / "Classes"/ "classes.jar" + if (stdLocation.asFile.exists()) + stdLocation + else if (osXLocation.asFile.exists()) + osXLocation + else + throw new IllegalStateException("Unknown location for rt.jar") + } + val proguard = TaskKey[Unit]("proguard") + val minJarPath = SettingKey[File]("min-jar-path") + + private implicit def pathEscape(p: File) = new { + def escaped: String = '"' + Path.absolute(p).toString.replaceAll("\\s", "\\ ") + '"' + } + + val proguardDefaultArgs = SettingKey[Seq[String]]("proguard-default-args") + val proguardOptions = SettingKey[Seq[String]]("proguard-options") + val makeInJarFilter = SettingKey[String => String]("makeInJarFilter") + + private val proguardArgs = TaskKey[List[String]]("proguard-args") + val proguardInJars = TaskKey[Seq[File]]("proguard-in-jars") + val proguardInJarsTask = TaskKey[Seq[File]]("proguard-in-jars-task") + val proguardLibraryJars = TaskKey[Seq[File]]("proguard-library-jars") + + def proguardInJarsTaskImpl: Initialize[Task[Seq[File]]] = { + (dependencyClasspath in Compile, proguardInJars, proguardLibraryJars) map { + (dc, pij, plj) => + import Build.data + data(dc).filterNot(plj.contains) ++ pij + } + } + + def proguardArgsTask: Initialize[Task[List[String]]] = { + (proguardLibraryJars, proguardInJarsTask, artifactPath in (Compile, packageBin), makeInJarFilter, minJarPath, proguardDefaultArgs, proguardOptions, packageBin in Compile, streams) map { + (plj, pij, jp, mijf, mjp, pda, po, pb, s) => + val proguardInJarsArg = { + val inPaths = pij.foldLeft(Map.empty[String, File])((m, p) => m + (p.getName -> p)).values.iterator + "-injars" :: (List(jp.escaped).iterator ++ inPaths.map(p => p.escaped+"("+mijf(p.asFile.getName)+")")).mkString(File.pathSeparator) :: Nil + } + val proguardOutJarsArg = "-outjars" :: mjp.escaped :: Nil + val proguardLibJarsArg = { + val libPaths = plj.foldLeft(Map.empty[String, File])((m, p) => m + (p.getName -> p)).values.iterator + if (libPaths.hasNext) "-libraryjars" :: libPaths.map(_.escaped).mkString(File.pathSeparator) :: Nil else Nil + } + val args = proguardInJarsArg ::: proguardOutJarsArg ::: proguardLibJarsArg ::: pda.toList ::: po.toList + s.log.debug("Proguard args: " + args) + args + } + } + + def proguardTask(args: List[String], bd: File) { + val config = new ProGuardConfiguration + new ConfigurationParser(args.toArray[String], bd, new Properties).parse(config) + new ProGuard(config).execute + } + + val proguardSettings = Seq( + minJarPath <<= (crossTarget, projectID, artifact, scalaVersion, artifactName) { (t, module, a, sv, toString) => + val scalaversion = ScalaVersion(sv, binaryScalaVersion(sv)) + t / toString(scalaversion, module.copy(revision = module.revision + ".min"), a) asFile + }, + proguardOptions := Nil, + makeInJarFilter := { (file) => "!META-INF/MANIFEST.MF" }, + proguardDefaultArgs := Seq("-dontwarn", "-dontoptimize", "-dontobfuscate"), + proguardLibraryJars := { (rtJarPath :PathFinder).get }, + proguardInJars <<= (scalaInstance) map { (si) => Seq(si.libraryJar) }, + proguardInJarsTask <<= proguardInJarsTaskImpl, + proguardArgs <<= proguardArgsTask, + proguard <<= (packageBin in Compile, proguardArgs in Compile, baseDirectory) map { (_, args, bd) => proguardTask(args, bd) } + ) +}