diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-04 03:02:04 +0000 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-04 20:43:25 -0500 |
commit | c6fd3f43a9d2b2f38442602769e920803a7d43ba (patch) | |
tree | e1561087d27c603075b89877213818603c3787d3 /plugins/proguard/templates | |
parent | 4bd0255f0a39d87652c032533ce45eb65e8f3b1e (diff) | |
download | cbt-c6fd3f43a9d2b2f38442602769e920803a7d43ba.tar.gz cbt-c6fd3f43a9d2b2f38442602769e920803a7d43ba.tar.bz2 cbt-c6fd3f43a9d2b2f38442602769e920803a7d43ba.zip |
separate type-safe proguard wrapper into self-contained library
also make logic to maintain auto-generated sections re-usable
Diffstat (limited to 'plugins/proguard/templates')
-rw-r--r-- | plugins/proguard/templates/Proguard.scala | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/plugins/proguard/templates/Proguard.scala b/plugins/proguard/templates/Proguard.scala deleted file mode 100644 index 23a3117..0000000 --- a/plugins/proguard/templates/Proguard.scala +++ /dev/null @@ -1,85 +0,0 @@ -package cbt -import java.io.File -import java.nio.file.Files.deleteIfExists - -sealed class KeepOptionModifier(val string: String) -object KeepOptionModifier{ -/* ${generated-top-level} */ -} - -trait Proguard extends BaseBuild { - def proguard( keep: (Seq[KeepOptionModifier], String) ) = { - ProguardLib(context.cbtLastModified, context.paths.mavenCache).proguard( - outjars = Seq( scalaTarget / "proguarded.jar" ), - injars = classpath, - libraryjars = Proguard.`rt.jar`, - keep = keep - ) - } -} - -object Proguard{ - val version = "5.3.2" - val `rt.jar` = ClassPath( Seq( new File(System.getProperty("java.home"),"lib/rt.jar") ) ) -} - -case class ProguardLib( - cbtLastModified: Long, mavenCache: File, - dependency: Option[DependencyImplementation] = None -)( - implicit logger: Logger, transientCache: java.util.Map[AnyRef,AnyRef], classLoaderCache: ClassLoaderCache -){ - /** - Typed interface on top of the proguard command line tool. - Check the official ProGuard docs for usage. - Use `Some(None)` to call an option without arguments. - Use `true` to set a flag. - - @see https://www.guardsquare.com/en/proguard/manual/refcard - @see https://www.guardsquare.com/en/proguard/manual/usage - -${generated-docs} - */ - case class proguard( -/* ${generated-args} */ - ) extends ( () => ClassPath ){ - - // type class rendering scala values into string arguments - private class valueToStrings[T]( val apply: T => Option[Seq[String]] ) - private object valueToStrings{ - def apply[T:valueToStrings](value: T) = implicitly[valueToStrings[T]].apply(value) - implicit object SeqFile extends valueToStrings[Seq[File]](v => Some(v.map(_.string))) - implicit object ClassPath extends valueToStrings[ClassPath](v => Some(Seq(v.string))) - implicit object File extends valueToStrings[File](v => Some(Seq(v.string))) - implicit object String extends valueToStrings[String](v => Some(Seq(v))) - implicit object Int extends valueToStrings[Int](i => Some(Seq(i.toString))) - implicit object Boolean extends valueToStrings[Boolean]({ - case false => None - case true => Some(Nil) - }) - implicit def Option2[T:valueToStrings]: valueToStrings[Option[T]] = new valueToStrings( - _.map(implicitly[valueToStrings[T]].apply(_).toSeq.flatten) - ) - implicit def Option3[T:valueToStrings]: valueToStrings[Option[Option[String]]] = new valueToStrings(_.map(_.toSeq)) - implicit def SpecWithModifiers: valueToStrings[(Seq[KeepOptionModifier], String)] = new valueToStrings({ - case (modifiers, spec) => Some( Seq( modifiers.map(_.string).map(","++_).mkString ).filterNot(_ == "") :+ spec ) - }) - } - - // capture string argument values and names - val capturedArgs = capture_args.captureArgs - - def apply: ClassPath = { - val args = capturedArgs.args.map(arg => arg.copy(name="-"++arg.name)).flatMap(_.toSeqOption).flatten - outjars.map(_.toPath).map(deleteIfExists) - val c = dependency getOrElse MavenResolver( cbtLastModified, mavenCache, mavenCentral ).bindOne( - MavenDependency("net.sf.proguard","proguard-base",Proguard.version) - ) runMain ( - "proguard.ProGuard", - args : _* - ) - if(c != ExitCode.Success) throw new Exception - ClassPath(outjars) - } - } -} |