Skip to content

Instantly share code, notes, and snippets.

@derkosak

derkosak/proguard.rb

Forked from aboisvert/proguard.rb
Last active Dec 16, 2015
Embed
What would you like to do?
#
# Usage:
#
# Add the following at the top of your buildfile,
#
# require 'proguard.rb'
#
# And specify your proguard jar in your project,
#
# package(:proguard).tap do |proguard|
# # add your project's compiled code as source
# proguard.dependencies << [compile.target]
# # or, add your project's final JAR artifact as source (-injars)
# proguard.dependencies << package(:jar).to_s
# # configure your project's dependencies
# proguard.libraries << ALL_THE_JARS
# # include configuration files (-include filename, or @filename)
# proguard.include << _('my_config.pro')
# # other options (e.g. '-printmapping mapping.txt', etc...)
# proguard.params << ["-verbose"]
# end
#
module Buildr
module Proguard
REQUIRES = [ "net.sf.proguard:proguard:jar:4.8" ]
Java.classpath << lambda { REQUIRES }
class ProguardTask < Rake::FileTask
attr_accessor :dependencies
attr_accessor :libraries
attr_accessor :params
attr_accessor :include
# attr_writer :package_resources
def initialize(*args)
super
@dependencies ||= []
@params ||= []
@include ||= []
@package_resources ||= true
rt_jar ||= begin
home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
['jre/lib/rt.jar', '../lib/rt.jar'].map { |path| File.expand_path(path, home) }.find { |path| File.exist?(path) }
end
@libraries ||= [rt_jar]
enhance do
Java.load
cmd_args = [
'-libraryjars', libraries.join(File::PATH_SEPARATOR),
'-injars', dependencies.join(File::PATH_SEPARATOR),
'-outjar', self.to_s,
]
# merges "-include filename" options
cmd_args << "-include #{Array(include).join(";")}" unless include.empty?
# merges general "-param" options
cmd_args << "#{Array(params).join(" ")}" unless params.empty?
trace "ProGuard.main #{cmd_args.inspect}"
Java.proguard.ProGuard.main(cmd_args.to_java(Java.java.lang.String))
end
end
end
end
def package_as_proguard(file_name)
Proguard::ProguardTask.define_task(file_name).tap do |proguard|
#proguard.dependencies = [compile.target]
#proguard.dependencies << [resources.target] if @package_resources
end
end
def package_as_proguard_spec(spec) #:nodoc:
spec.merge(:type => :jar)
end
class Project
include Proguard
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.