Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to ProGuard 4.8 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
project/target
project/project
lib_managed

124 changes: 62 additions & 62 deletions project/Build.scala
Original file line number Diff line number Diff line change
@@ -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(
<url>http://github.com/siasia/xsbt-web-plugin</url>,
<licenses>
<license>
<name>GPLv2</name>
<url>http://www.gnu.org/licenses/gpl-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>,
<scm>
<connection>scm:git:[email protected]:siasia/xsbt-proguard-plugin.git</connection>
<developerConnection>scm:git:[email protected]:siasia/xsbt-proguard-plugin.git</developerConnection>
<url>[email protected]:siasia/xsbt-proguard-plugin.git</url>
</scm>,
<developers>
<developer>
<id>siasia</id>
<name>Artyom Olshevskiy</name>
<email>[email protected]</email>
</developer>
</developers>,
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
)
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(
<url>http://github.com/siasia/xsbt-web-plugin</url>,
<licenses>
<license>
<name>GPLv2</name>
<url>http://www.gnu.org/licenses/gpl-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>,
<scm>
<connection>scm:git:[email protected]:siasia/xsbt-proguard-plugin.git</connection>
<developerConnection>scm:git:[email protected]:siasia/xsbt-proguard-plugin.git</developerConnection>
<url>[email protected]:siasia/xsbt-proguard-plugin.git</url>
</scm>,
<developers>
<developer>
<id>siasia</id>
<name>Artyom Olshevskiy</name>
<email>[email protected]</email>
</developer>
</developers>,
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
)
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 :_*)
}
203 changes: 102 additions & 101 deletions src/main/scala/ProguardPlugin.scala
Original file line number Diff line number Diff line change
@@ -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) }
)
}