Created
November 7, 2012 02:31
-
-
Save cessationoftime/4029263 to your computer and use it in GitHub Desktop.
Merge reference.conf for proguard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//xsbt-proguard-plugin | |
seq(ProguardPlugin.proguardSettings :_*) | |
//filter resource files from JARs | |
makeJarFilter <<= (makeJarFilter) { | |
(makeFilter) => | |
val (makeInJarFilter,makeOutJarFilter) = makeFilter; | |
val akkas = List("akka-remote","akka-actor", "akka-agent", "akka-camel", "akka-amqp") | |
val InFilter = | |
(file:String) => file match { | |
case "application.conf" => makeInJarFilter(file) | |
case x if akkas.exists(ak=>x.contains(ak)) => makeInJarFilter(file) + ",!reference.conf" | |
case _ => makeInJarFilter(file) | |
}; | |
val OutFilter = | |
(file:String) => file match { | |
case "node_2.9.1-0.0.1-SNAPSHOT.min.jar" => "!common.conf" | |
case _ => makeOutJarFilter(file) | |
}; | |
(InFilter,OutFilter) | |
} | |
//filter files in output JARS to remove common.conf and application.conf | |
//ADD SBT Generated resource files to ClassPath for Proguard to use them | |
// | |
//Add Akka Merged reference.conf file | |
// | |
proguardOptions ++= Seq( | |
"-printconfiguration proguardGeneratedConfig.txt", | |
//Specifies the base directory for all subsequent relative file names in these configuration arguments or this configuration file. | |
"-libraryjars <java.home>/lib/rt.jar(java/**,javax/**)", | |
//"-keepattributes Exceptions", | |
//need to reduce this: | |
"-keep class scala.concurrent.stm.ccstm.CCSTM { *; }", | |
"-keep class * implements java.sql.Driver", | |
"-keep class com.mysql.jdbc.log.StandardLogger { *; }", | |
//Slf4JLogger may need to be kept if you receive a NoClassDefFoundError on the SQLError class when using more advanced logging | |
//"-keep class com.mysql.jdbc.log.Slf4JLogger { *; }", | |
"-keep public class net.sf.cglib.core.ReflectUtils { public static java.lang.reflect.Method[] findMethods(java.lang.String[],java.lang.reflect.Method[]); }", | |
"-keep public class net.sf.cglib.proxy.MethodProxy { public static net.sf.cglib.proxy.MethodProxy create(java.lang.Class, java.lang.Class, java.lang.String, java.lang.String, java.lang.String); }", | |
"-keep public class net.sf.cglib.proxy.MethodInterceptor { public java.lang.Object intercept(java.lang.Object, java.lang.reflect.Method, java.lang.Object[],net.sf.cglib.proxy.MethodProxy); }", | |
"-keep public class net.sf.cglib.reflect.FastClass { protected <init>(java.lang.Class); }", | |
"-keep class akka.remote.RemoteActorRefProvider { *; }", | |
"-keep class akka.event.Logging$DefaultLogger { *; }", | |
"-keep class akka.event.Logging$LogExt { *; }", | |
"-keep class akka.event.slf4j.Slf4jEventHandler { *; }", | |
"-keep class akka.remote.netty.NettyRemoteTransport { *; }", | |
"-keep class akka.serialization.JavaSerializer { *; }", | |
"-keep class akka.serialization.ProtobufSerializer { *; }", | |
"-keep class com.google.protobuf.* { *; }" | |
) | |
Commands.proguardOutputRename := "signed-min.jar" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._; | |
import Keys._ | |
import Project.Initialize | |
import classpath.ClasspathUtilities | |
import ProguardPlugin._ | |
import Signing._ | |
import scala.collection.immutable.StringLike | |
import com.typesafe.config.ConfigFactory | |
import com.typesafe.config.ConfigParseOptions | |
import com.typesafe.config.ConfigResolveOptions | |
object AkkaConfig { | |
def stripComments(mergedConfigString : StringLike[_]) : String = { | |
val Rege = """^\s*#.*""".r | |
val nc : Iterator[String]= mergedConfigString.lines; | |
val noComments = nc.flatMap (_ match { | |
case Rege() => None | |
case x => Some(x) | |
}) | |
noComments.mkString("\n") | |
} | |
/** | |
* get the merged version of the default settings (from the reference.conf files in the JARs on the classpath) | |
*/ | |
def mergedConfig : String = { | |
//load application.conf and then use .withFallback() on the reference.conf object | |
val referenceConfig = ConfigFactory.parseResourcesAnySyntax(getClass,"/reference", ConfigParseOptions.defaults) | |
val applicationConfig = ConfigFactory.parseFile(new java.io.File("messaging/src/main/resources/common.conf"), ConfigParseOptions.defaults)//.getConfig(configName) | |
val mergedConfig = applicationConfig.withFallback(referenceConfig) | |
val mergedConfigString :StringLike[_] = mergedConfig.root.render; | |
stripComments(mergedConfigString) | |
} | |
lazy val akkaMergedRefConfigKey = TaskKey[Seq[java.io.File]]("merge-akka-refconfig","pulls the reference.conf files from akka jars and merges them into a new reference.conf file for inclusion later in the proguard output") | |
lazy val akkaMergedRefConfigTask = akkaMergedRefConfigKey <<= (resourceManaged) map { (managedResourceDir : File)=> | |
val targetFile = managedResourceDir / "reference.conf"; | |
println("Preparing to write merged akka reference.conf:\n" + targetFile) | |
IO write (targetFile, mergedConfig) | |
Seq(targetFile.asFile) | |
} | |
} | |
object Commands extends Build { | |
import AkkaConfig._ | |
val proguardOutputRename = SettingKey[String]("proguard-output-rename","final name of the proguarded jar") | |
val runMinjarKey = TaskKey[Unit]("run-minjar","executes the mainClass of the proguarded .min.jar file"); | |
val runSignedMinJarKey = TaskKey[Unit]("run-signed-minjar","execute the mainClass of the proguarded Jar (the webstart/*.min.jar)"); | |
//chain proguard and webstart together sequentially so webstart depends on proguard | |
val proguardThenWebstartKey = TaskKey[File]("proguard-webstart", "execute 'proguard' then sign the result with 'webstart-singlejar'"); | |
val proguardThenWebstartTask = proguardThenWebstartKey <<= webstartSingleJarBuild.dependsOn(renameProguardOutputKey) | |
lazy val renameProguardOutputKey = TaskKey[Unit]("rename-proguard-output","copied the proguarded jar with a new name") | |
//alias for rename-signed-jar-name | |
lazy val signMinJarKey = TaskKey[File]("sign-minjar", "execute 'proguard' then sign the result (and create jnlp file) with 'webstart-singlejar'"); | |
lazy val signMinJarTask = signMinJarKey <<=proguardThenWebstartKey; | |
//execute the mainClass of the proguarded Jar (the .min.jar) | |
lazy val runMinjarTask = runMinjarKey <<= (minJarPath,proguard) map { (minJar:File,p)=> | |
List("java", "-jar", minJar.toString) ! ; //execute console command to launch jar | |
} | |
//could say runMinjarKey.dependsOn(proguard), but I have it mapped instead which is the same effect | |
//execute the mainClass of the proguarded Jar (the webstart/*.min.jar) | |
//lazy val runSignedMinJarTask = runSignedMinJarKey <<= (webstartSingleJar,webstartOutputDirectory,proguardThenWebstartKey) map { (minJarName,outputDirectory,sjb)=> | |
lazy val runSignedMinJarTask = runSignedMinJarKey <<= (webstartSingleJar,webstartOutputDirectory,proguardThenWebstartKey) map { (minJarName,outputDirectory,sjb)=> | |
List("java", "-jar", outputDirectory.toString + "/" + minJarName) ! ; //execute console command to launch jar | |
} | |
lazy val renameProguardOutputTask = renameProguardOutputKey <<= (proguard,minJarPath,crossTarget,proguardOutputRename) map { (doProguard,minJar:File,crossDir,newName)=> | |
List("cp", minJar.toString, crossDir.toString + "/" + newName) ! ; //execute console command to launch jar | |
} | |
val webDeployKey = TaskKey[Unit]("web-deploy","copies the contents of crossTarget/webstart/ to the intraqa server"); | |
//val webDeployFolder = SettingKey[String]("intraqa-folder","location on the intraqa server to copy output to"); | |
lazy val webDeployTask = webDeployKey <<= (baseDirectory,crossTarget,proguardThenWebstartKey,Keys.streams) map { (baseDir,crossDir,doSigning,streams: TaskStreams)=> | |
//require(destinationLoc != null, intraQAFolder.key.label + " must be defined"); | |
//require(destinationLoc(0) == '/', intraQAFolder.key.label + " must start with a /"); | |
val dest = baseDir.toString + "/../applet/applet.jar" | |
val sourceLoc = crossDir.toString + "/webstart/signed-min.jar" | |
List("cp", sourceLoc,dest) ! ; //execute console command to launch jar | |
streams.log info ("copied: '" + sourceLoc + "' -> '" + dest + "'") | |
} | |
val tasks = Seq(signMinJarTask,proguardThenWebstartTask,runMinjarTask,runSignedMinJarTask,renameProguardOutputTask,webDeployTask) | |
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
//need a command that will run the tests against the proguarded and signed jar | |
//the project definition (if this were a multi-project build it would be the root project) | |
Seq(signMinJarTask,proguardThenWebstartTask,runMinjarTask,runSignedMinJarTask,renameProguardOutputTask,intraQATask) | |
// ) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" | |
//akka JARs which will have reference.conf files merged into the proguard output reference.conf file | |
libraryDependencies ++= Seq( | |
"com.amazonaws" % "aws-java-sdk" % "1.3.21", | |
"com.typesafe.akka" % "akka-actor_2.10.0-RC1" % "2.1.0-RC1", // ApacheV2 | |
"com.typesafe.akka" % "akka-remote_2.10.0-RC1" % "2.1.0-RC1", // ApacheV2 | |
"com.typesafe.akka" % "akka-agent_2.10.0-RC1" % "2.1.0-RC1", // ApacheV2 | |
"com.typesafe.akka" % "akka-slf4j_2.10.0-RC1" % "2.1.0-RC1" // ApacheV2 | |
) | |
resolvers += Classpaths.typesafeResolver | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
object PluginDef extends Build { | |
override def projects = Seq(root) | |
lazy val root = Project("plugins", file(".")) dependsOn(proguard) | |
lazy val proguard = uri("git://github.com/cessationoftime/xsbt-proguard-plugin.git#scala210") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment