rake-ant-1.0.4/0000755000175000017500000000000013775160516013155 5ustar utkarshutkarshrake-ant-1.0.4/Rakefile0000644000175000017500000000027313775160516014624 0ustar utkarshutkarshrequire "bundler/gem_tasks" task :default => :test require "rake/testtask" Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList['test/test*.rb'] t.verbose = true end rake-ant-1.0.4/.gitignore0000644000175000017500000000012713775160516015145 0ustar utkarshutkarsh/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ rake-ant-1.0.4/Gemfile0000644000175000017500000000024313775160516014447 0ustar utkarshutkarshsource "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in rake-ant.gemspec gemspec rake-ant-1.0.4/rake-ant.gemspec0000644000175000017500000000144313775160516016226 0ustar utkarshutkarsh# coding: utf-8 lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "rake/ant/version" Gem::Specification.new do |spec| spec.name = "rake-ant" spec.version = Rake::Ant::VERSION spec.authors = ["Thomas E Enebo", "Charles Oliver Nutter"] spec.email = ["tom.enebo@gmail.com", "headius@headius.com"] spec.summary = %q{Ant tasks and integration for Rake} spec.homepage = "https://github.com/jruby/rake-ant" spec.license = "EPL-2.0" spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) end spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.15" spec.add_development_dependency "rake", "~> 10.0" end rake-ant-1.0.4/README.md0000644000175000017500000000063213775160516014435 0ustar utkarshutkarsh# Rake::Ant This package provides a wrapper and Rake tasks for using Ant from any Rake build. ## Installation Add this line to your application's Gemfile: ```ruby gem 'rake-ant' ``` And then execute: $ bundle Or install it yourself as: $ gem install rake-ant ## Usage Add usage info. ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/jruby/rake-ant. rake-ant-1.0.4/LICENSE0000644000175000017500000002710013775160516014162 0ustar utkarshutkarshEclipse Public License - v 1.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 1. DEFINITIONS "Contribution" means: a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and b) in the case of each subsequent Contributor: i) changes to the Program, and ii) additions to the Program; where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. "Contributor" means any person or entity that distributes the Program. "Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. "Program" means the Contributions distributed in accordance with this Agreement. "Recipient" means anyone who receives the Program under this Agreement, including all Contributors. 2. GRANT OF RIGHTS a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. 3. REQUIREMENTS A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: a) it complies with the terms and conditions of this Agreement; and b) its license agreement: i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. When the Program is made available in source code form: a) it must be made available under this Agreement; and b) a copy of this Agreement must be included with each copy of the Program. Contributors may not remove or alter any copyright notices contained within the Program. Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. 4. COMMERCIAL DISTRIBUTION Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. 5. NO WARRANTY EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. 6. DISCLAIMER OF LIABILITY EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 7. GENERAL If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. rake-ant-1.0.4/lib/0000755000175000017500000000000013775160516013723 5ustar utkarshutkarshrake-ant-1.0.4/lib/ant.rb0000644000175000017500000000002213775160516015024 0ustar utkarshutkarshrequire 'rake/ant'rake-ant-1.0.4/lib/rake/0000755000175000017500000000000013775160516014645 5ustar utkarshutkarshrake-ant-1.0.4/lib/rake/ant.rb0000644000175000017500000000414413775160516015757 0ustar utkarshutkarshrequire "rake" require "rake/ant/version" class Rake::Ant def self.load_from_ant IO.popen("#{ant_script} -diagnostics") do |diag| classpath_jars = [] listing_path = nil jar_path = nil diag.readlines.each do |line| # workaround for JRUBY-4814 (IO.popen doesnt convert CRLF to LF on Windows) line.chomp! if line =~ /^ant\.home: (.*)$/ && !defined?(ANT_HOME) const_set(:ANT_HOME, $1) elsif line =~ /Tasks availability/ break elsif line =~ /^ (.*) jar listing$/ listing_path = $1 elsif line =~ /^(.*\.home): (.*)$/ home_var, path = $1, $2 jar_path = listing_path.sub(home_var.upcase.sub('.','_'), path) if listing_path elsif line =~ /^ant\.core\.lib: (.*)$/ classpath_jars << $1 elsif line =~ /^(.*\.jar) \(\d+ bytes\)/ classpath_jars << File.join(jar_path, $1) end end classpath_jars.uniq.each {|j| $CLASSPATH << j } end rescue Errno::ENOENT raise RuntimeError, "Could not execute `#{ant_script}`. Make sure Ant is installed on the local system." end def self.load if ENV['ANT_HOME'] && File.exist?(ENV['ANT_HOME']) const_set(:ANT_HOME, ENV['ANT_HOME']) Dir["#{ANT_HOME}/lib/*.jar"].each {|j| $CLASSPATH << j } else load_from_ant end # Explicitly add javac path to classpath. # 'java.home' usually contains the JRE home on Windows and Linux. We # want the directory above that which contains lib/tools.jar. java_home = ENV['JAVA_HOME'] || ENV_JAVA['java.home'].sub(/\/jre$/,'') if java_home && File.exist?(java_home) const_set(:JAVA_HOME, java_home) load_if_exist "#{java_home}/lib/tools.jar" load_if_exist "#{java_home}/lib/classes.zip" end end def self.load_if_exist(jar) $CLASSPATH << jar if File.exist?(jar) end def self.ant_script require 'rbconfig' RbConfig::CONFIG['host_os'] =~ /Windows|mswin/ ? 'ant.bat' : 'ant' end load end # For backward compatibility Ant = Rake::Ant require 'rake/ant/ant' require 'rake/ant/rake' if defined?(::Rake) rake-ant-1.0.4/lib/rake/ant/0000755000175000017500000000000013775160516015427 5ustar utkarshutkarshrake-ant-1.0.4/lib/rake/ant/version.rb0000644000175000017500000000007013775160516017436 0ustar utkarshutkarshmodule Rake class Ant VERSION = "1.0.4" end end rake-ant-1.0.4/lib/rake/ant/tasks/0000755000175000017500000000000013775160516016554 5ustar utkarshutkarshrake-ant-1.0.4/lib/rake/ant/tasks/raketasks.rb0000644000175000017500000000106213775160516021070 0ustar utkarshutkarshrequire 'rubygems' require 'rake' require 'ant' class RakeWrapper def load_tasks(*args) # FIXME: Use our arguments (this sucks...let's submit a patch for Rake ARGV.clear ARGV.concat args Rake.application.tap do |application| application.init application.load_rakefile end end def execute(*args) load_tasks(*args).top_level end def invoke_task(task) Rake.application[task].invoke end def import(*args) ant = Ant.new load_tasks(*args).tasks.each { |rake_task| ant.add_target rake_task } end end rake-ant-1.0.4/lib/rake/ant/ant.rb0000644000175000017500000001516513775160516016546 0ustar utkarshutkarshbegin require 'rake/ant/element' rescue NameError => ne # uncaught, we should get a NameError, such as: # NameError: uppercase package names not accessible this way (`org.apache.tools.ant.IntrospectionHelper') # this probably means $ANT_HOME is not set properly raise RuntimeError, "Caught NameError; examine $ANT_HOME" end require 'rake/ant/target' class Rake::Ant java_import org.apache.tools.ant.DefaultLogger java_import org.apache.tools.ant.Location java_import org.apache.tools.ant.Project java_import org.apache.tools.ant.ProjectHelper attr_reader :project, :log, :location attr_accessor :current_target def initialize(options={}, &block) @options = options @location = Ant.location_from_caller @project = create_project options @current_target = nil generate_methods @project.data_type_definitions generate_methods @project.task_definitions process_arguments unless options[:run] == false || Ant.run || @location.file_name != $0 define_tasks(&block) end def properties @project.properties end def define_tasks(&code) code.arity == 1 ? code[self] : instance_eval(&code) if code end # Add a target (two forms) # 1. Execute a block as a target: add_target "foo-target" { echo :message => "I am cool" } # 2. Execute a rake task as a target: add_target Rake.application["default"] def add_target(*options, &block) target = options.first.respond_to?(:name) ? RakeTarget.new(self, options.first) : BlockTarget.new(self, *options, &block) @project.add_target target end alias target add_target def [](name) if @project.targets.containsKey(name.to_s) TargetWrapper.new(@project, name) else MissingWrapper.new(@project, name) end end def execute_target(name) self[name].execute end def execute_default @project.execute_target(@project.default_target) end def project_help max_width = @project.targets.keys.max {|a,b| a.length <=> b.length}.length @project.targets.values.select {|t| t.description }.sort{|a,b| a.name <=> b.name }.map {|t| "%-#{max_width}s - %s" % [t.name, t.description] }.join("\n") end def ant(*args) raise "ant is known to be broken and is unsupported in the ant library" end def antcall(*args) raise "antcall is known to be broken and is unsupported in the ant library" end def _element(name, args = {}, &block) Element.new(self, name).call(@current_target, args, &block) end def method_missing(name, *args, &block) project.log "invoking method_missing: #{name} on Ant instance", 5 _element(name, *args, &block) end def run(*targets) if targets.length > 0 targets.each {|t| execute_target(t) } else execute_default end end def process_arguments(argv = ARGV, run_at_exit = true) properties = [] targets = [] argv.each {|a| a =~ /^-D/ ? properties << a[2..-1] : targets << a } properties.each do |p| key, value = p.split('=', 2) value ||= "true" @project.set_user_property(key, value) end at_exit do begin run(*targets) if (!targets.empty? || @project.default_target) && !Ant.run rescue => e warn e.message puts e.backtrace.join("\n") if $DEBUG exit 1 end end if run_at_exit end private def create_project(options) # If we are calling into a rakefile from ant then we already have a project to use return $project if defined?($project) && $project options[:basedir] ||= '.' output_level = options.delete(:output_level) || 2 Project.new.tap do |p| p.init p.add_build_listener(DefaultLogger.new.tap do |log| log.output_print_stream = Java::java.lang.System.out log.error_print_stream = Java::java.lang.System.err log.emacs_mode = true log.message_output_level = output_level @log = log end) helper = ProjectHelper.getProjectHelper helper.import_stack.add(Java::java.io.File.new(@location.file_name)) p.addReference(ProjectHelper::PROJECTHELPER_REFERENCE, helper) options.each_pair {|k,v| p.send("set_#{k}", v) if p.respond_to?("set_#{k}") } end end def generate_methods(collection) existing_methods = Ant.instance_methods(false) collection.each do |name, clazz| element = Element.new(self, name, clazz) method_name = Ant.safe_method_name(name) (class << self; self; end).send(:define_method, method_name) do |*a, &b| element.call(@current_target, *a, &b) end unless existing_methods.include?(method_name) end end class << self attr_accessor :run def safe_method_name(element_name) if element_name =~ /\A(and|or|not|do|end|if|else)\z/m "_#{element_name}" else element_name end end def location_from_caller file, line = caller.detect{|el| el !~ /^#{File.dirname(__FILE__)}/ && el !~ /\.java:/}.split(/:(\d+):?/) Location.new(file, line.to_i, 1) end def ant(options={}, &code) if options.respond_to? :to_hash @ant ||= Ant.new options.to_hash @ant.define_tasks(&code) @ant else options = options.join(" ") if options.respond_to? :to_ary ant_bin = ENV['ANT_HOME'] ? File.join(ENV['ANT_HOME'], 'bin', 'ant') : 'ant' # find one on $PATH system "#{ant_bin} #{options.to_s}" # FIXME: Make this more secure if using array form end rescue Exception => e warn e.message warn e.backtrace.join("\n") end end end # This method has three different uses: # # 1. Call an ant task or type directly: # task :compile do # Rake task # ant.javac { } # Look I am calling an ant task # end # 2. Provide a block to provide an impromptu ant session # ant do # javac {} # Everything executes as if in an executing ant target # end # 3. Provide arguments to execute ant as it's own build # ant '-f my_build.xml my_target1' # # Additionally this may be passed in array format if you are worried about injection: # # args = ['-f', 'my_build.xml', 'my_target1'] # ant args # def ant(*args, &block) Rake::Ant.ant(*args, &block) end # Need Rake DSL at top-level for "task" and other methods. require 'rake/dsl_definition' include Rake::DSL def ant_import(filename = 'build.xml') ant = Rake::Ant.ant abs_name = File.expand_path(filename) Rake::Ant::ProjectHelper.configure_project ant.project, java.io.File.new(abs_name) ant.project.targets.each do |target_name, target| name = Rake.application.lookup(target_name) ? "ant_" + target_name : target_name task(name) { target.project.execute_target(target_name) } end end rake-ant-1.0.4/lib/rake/ant/element.rb0000644000175000017500000000704713775160516017415 0ustar utkarshutkarshclass Rake::Ant java_import org.apache.tools.ant.IntrospectionHelper java_import org.apache.tools.ant.RuntimeConfigurable java_import org.apache.tools.ant.UnknownElement # preserve idempotence of Ruby wrapper as much as possible UnknownElement.__persistent__ = true class UnknownElement attr_accessor :ant, :nesting # undef some method names that might collide with ant task/type names %w(test fail abort raise exec trap).each {|m| undef_method(m)} Object.instance_methods.grep(/java/).each {|m| undef_method(m)} def _element(name, args = {}, &block) Element.new(ant, name).call(self, args, &block) end def method_missing(name, *args, &block) ant.project.log "#{location.to_s}: #{' ' * nesting}#{task_name} -> #{name}", 5 _element(name, *args, &block) end end # This is really the metadata of the element coupled with the logic for # instantiating an instance of an element and evaluating it. My intention # is to decouple these two pieces. This has extra value since we can then # also make two types of instances for both top-level tasks and for targets # since we have some conditionals which would then be eliminated class Element attr_reader :name def initialize(ant, name, clazz = nil) @ant, @name, @clazz = ant, name, clazz end def call(parent, args={}, &code) element = create_element(parent) assign_attributes element, args define_nested_elements element if @clazz code.arity==1 ? code[element] : element.instance_eval(&code) if block_given? if parent.respond_to? :add_child # Task parent.add_child element parent.runtime_configurable_wrapper.add_child element.runtime_configurable_wrapper elsif parent.respond_to? :add_task # Target parent.add_task element else # Just run it now @ant.project.log "#{element.location.to_s}: Executing #{name}", 5 element.owning_target = Target.new.tap {|t| t.name = ""} element.maybe_configure element.execute end end private def create_element(parent) # See ProjectHelper2.ElementHandler UnknownElement.new(@name).tap do |e| if parent.respond_to?(:nesting) e.nesting = parent.nesting + 1 else e.nesting = 1 end e.ant = @ant e.project = @ant.project e.task_name = @name e.location = Ant.location_from_caller e.owning_target = @ant.current_target end end # This also subsumes configureId to only have to traverse args once def assign_attributes(instance, args) wrapper = RuntimeConfigurable.new instance, instance.task_name args.each do |key, value| wrapper.set_attribute to_string(key), @ant.project.replace_properties(to_string(value)) end end def define_nested_elements(instance) meta_class = class << instance; self; end @helper = IntrospectionHelper.get_helper(@ant.project, @clazz) @helper.get_nested_element_map.each do |element_name, clazz| element = Element.new(@ant, element_name, clazz) meta_class.send(:define_method, Ant.safe_method_name(element_name)) do |*args, &block| instance.ant.project.log "#{instance.location.to_s}: #{' ' * instance.nesting}#{instance.task_name} . #{element_name}", 5 element.call(instance, *args, &block) end end end def to_string(value) if String === value value elsif value.respond_to?(:to_str) value.to_str else value.to_s end end end end rake-ant-1.0.4/lib/rake/ant/target.rb0000644000175000017500000000547013775160516017250 0ustar utkarshutkarshrequire 'java' class Rake::Ant java_import org.apache.tools.ant.Target class RakeTarget < Target ALREADY_DEFINED_PREFIX = "rake_" def initialize(ant, rake_task) super() set_project ant.project set_name generate_unique_target_name rake_task.name rake_task.prerequisites.each { |prereq| add_dependency prereq } @rake_task = rake_task end def execute @rake_task.execute end private def generate_unique_target_name(name) # FIXME: This is not guaranteed to be unique and may be a wonky naming convention? if project.targets.get(name) project.log "ant already defines #{name}. Redefining as #{ALREADY_DEFINED_PREFIX}#{name}" name = ALREADY_DEFINED_PREFIX + name end name end end class BlockTarget < Target def initialize(ant, *options, &block) super() set_project ant.project hash = extract_options(options) hash.each_pair {|k,v| send("set_#{k}", v) } @ant, @block = ant, block end def execute # Have to dupe this logic b/c Ant doesn't provide a way to # override inner part of execute if_cond, unless_cond = if_condition, unless_condition if if_cond && unless_cond execute_target elsif !if_cond project.log(self, "Skipped because property '#{if_cond}' not set.", Project::MSG_VERBOSE) else project.log(self, "Skipped because property '#{unless_cond}' set.", Project::MSG_VERBOSE) end end def defined_tasks define_target.tasks end private def extract_options(options) hash = Hash === options.last ? options.pop : {} hash[:name] = options[0].to_s if options[0] hash[:description] = options[1].to_s if options[1] hash end def if_condition cond = get_if return true unless cond val = project.replace_properties(cond) project.get_property(val) && val end def unless_condition cond = get_unless return true unless cond val = project.replace_properties(cond) project.get_property(val).nil? && val end def execute_target @ant.instance_eval(&@block) if @block end def define_target Target.new.tap do |t| t.name = "" begin @ant.current_target = t execute_target ensure @ant.current_target = nil end end end end class TargetWrapper def initialize(project, name) @project, @name = project, name end def execute @project.execute_target(@name) end end class MissingWrapper def initialize(project, name) @project_name = project.name || "" @name = name end def execute raise "Target `#{@name}' does not exist in project `#{@project_name}'" end end end rake-ant-1.0.4/lib/rake/ant/rake.rb0000644000175000017500000000021513775160516016674 0ustar utkarshutkarshdef ant_task(*args, &block) task(*args) do |t| ant.define_tasks(&block) end end class FileList def to_str join(',') end end rake-ant-1.0.4/lib/rake/ant/project_converter.rb0000644000175000017500000000425313775160516021515 0ustar utkarshutkarshrequire 'rexml/parsers/sax2parser' require 'rexml/sax2listener' require 'rake/ant' class Rake::Ant class ProjectConverter include REXML::SAX2Listener def initialize @output = $stdout @depth = 0 @seen = ['', 0] end def start_element(uri, localname, qname, attributes) emit_do(localname) case localname when "project" @output.puts "require 'ant'" emit "ant", attributes when "description" print_with_indent "project.description = " else emit localname, attributes end @depth += 1 end def end_element(uri, localname, qname) @depth -= 1 emit_end(localname) end def characters(text) @output.print value_inspect(text.strip) if text.strip.length > 0 end def emit_do(tag) @output.puts " do" if @seen.last[1] != @depth @seen << [tag, @depth] end def emit_end(tag) level = @seen.last if level[0] == tag && level[1] == @depth @output.puts else print_with_indent "end\n" @seen << ["/#{tag}", @depth] end end def emit(code, attributes = nil) print_with_indent safe_method_name(code, attributes) if attributes first = true attributes.each do |k,v| @output.print "," unless first @output.print " #{symbol_or_string(k)} => #{value_inspect(v)}" first = false end end end def print_with_indent(str) @output.print " " * @depth @output.print str end ID = /\A[a-zA-Z_][a-zA-Z0-9_]*\z/ def symbol_or_string(s) if s =~ ID ":#{s}" else s.inspect end end def value_inspect(s) s.inspect.gsub("\\n", "\n") end def safe_method_name(s, attributes) s = Ant.safe_method_name(s) if s =~ ID s else "_element #{s.inspect}#{attributes.nil? || attributes.empty? ? '' : ','}" end end def self.convert(file = "build.xml") source = File.exists?(file) ? File.new(file) : $stdin parser = REXML::Parsers::SAX2Parser.new source parser.listen self.new parser.parse end end end