Class: PomLoader::Loader
- Inherits:
-
Object
- Object
- PomLoader::Loader
- Defined in:
- lib/pom-loader.rb
Instance Attribute Summary collapse
-
#loaded ⇒ Object
Returns the value of attribute loaded.
-
#log4j_xml_file ⇒ Object
Returns the value of attribute log4j_xml_file.
-
#mvn_exe ⇒ Object
Returns the value of attribute mvn_exe.
-
#mvn_repo_dir ⇒ Object
Returns the value of attribute mvn_repo_dir.
-
#pom_changed_at ⇒ Object
Returns the value of attribute pom_changed_at.
-
#pom_dir ⇒ Object
Returns the value of attribute pom_dir.
-
#target_classes_dir ⇒ Object
Returns the value of attribute target_classes_dir.
Instance Method Summary collapse
- #add_jars_to_classpath ⇒ Object
- #build_classpath ⇒ Object
- #build_effective_pom ⇒ Object
-
#initialize(options = {}) ⇒ Loader
constructor
note: mvn_repo_dir has absolutely no impact on anything.
-
#load ⇒ Object
Load dependency jars onto classpath specified by a maven pom.xml file.
- #load_logger ⇒ Object
- #parse_effective_pom ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Loader
note: mvn_repo_dir has absolutely no impact on anything.
38 39 40 41 42 43 44 |
# File 'lib/pom-loader.rb', line 38 def initialize( = {}) @pom_dir = [:pom_dir] || Dir.pwd @mvn_repo_dir = [:mvn_repo_dir] || (Dir.home + '/.m2/repository') @target_classes_dir = [:target_classes_dir] || (@pom_dir + '/target/classes') @log4j_xml_file = [:log4j_xml_file] || "#{@target_classes_dir}/com/homeaway/log4j.xml" @mvn_exe = [:mvn_exe] || ENV['MVN2_EXE'] || 'mvn' end |
Instance Attribute Details
#loaded ⇒ Object
Returns the value of attribute loaded.
28 29 30 |
# File 'lib/pom-loader.rb', line 28 def loaded @loaded end |
#log4j_xml_file ⇒ Object
Returns the value of attribute log4j_xml_file.
28 29 30 |
# File 'lib/pom-loader.rb', line 28 def log4j_xml_file @log4j_xml_file end |
#mvn_exe ⇒ Object
Returns the value of attribute mvn_exe.
28 29 30 |
# File 'lib/pom-loader.rb', line 28 def mvn_exe @mvn_exe end |
#mvn_repo_dir ⇒ Object
Returns the value of attribute mvn_repo_dir.
28 29 30 |
# File 'lib/pom-loader.rb', line 28 def mvn_repo_dir @mvn_repo_dir end |
#pom_changed_at ⇒ Object
Returns the value of attribute pom_changed_at.
28 29 30 |
# File 'lib/pom-loader.rb', line 28 def pom_changed_at @pom_changed_at end |
#pom_dir ⇒ Object
Returns the value of attribute pom_dir.
28 29 30 |
# File 'lib/pom-loader.rb', line 28 def pom_dir @pom_dir end |
#target_classes_dir ⇒ Object
Returns the value of attribute target_classes_dir.
28 29 30 |
# File 'lib/pom-loader.rb', line 28 def target_classes_dir @target_classes_dir end |
Instance Method Details
#add_jars_to_classpath ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/pom-loader.rb', line 86 def add_jars_to_classpath time = Benchmark.realtime do File.readlines("#{@pom_dir}/target/build-classpath.txt").each do |line| line.split(':').each do |jar| $CLASSPATH << jar end end $CLASSPATH << @target_classes_dir if Dir.exists? @target_classes_dir end puts "Added java paths to $CLASSPATH in #{time}" end |
#build_classpath ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pom-loader.rb', line 75 def build_classpath time = Benchmark.realtime do build_classpath = "#{@pom_dir}/target/build-classpath.txt" if !File.exists?(build_classpath) || File.ctime(build_classpath) < @pom_changed_at process_output = `#{@mvn_exe} -f #{@pom_dir}/pom.xml dependency:build-classpath -DincludeTypes=jar -Dmdep.outputFile=#{build_classpath}` puts process_output unless $?.success? end end puts "Built build-classpath.txt in #{time}s" end |
#build_effective_pom ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pom-loader.rb', line 64 def build_effective_pom time = Benchmark.realtime do effective_pom_path = "#{@pom_dir}/target/effective-pom.xml" if !File.exists?(effective_pom_path) || File.ctime(effective_pom_path) < @pom_changed_at process_output = `#{mvn_exe} -f #{@pom_dir}/pom.xml help:effective-pom -Doutput=#{effective_pom_path}` puts process_output unless $?.success? end end puts "Built effective-pom.xml in #{time}s" end |
#load ⇒ Object
Load dependency jars onto classpath specified by a maven pom.xml file
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pom-loader.rb', line 47 def load if File.exists? "#{pom_dir}/pom.xml" @pom_changed_at = File.ctime("#{pom_dir}/pom.xml") puts "Loading java environment from #{@pom_dir}/pom.xml" build_effective_pom build_classpath add_jars_to_classpath parse_effective_pom load_logger if File.exists? @log4j_xml_file @loaded = true else @loaded = false puts "Not loading java environment. pom dir=#{@pom_dir}" end self end |
#load_logger ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/pom-loader.rb', line 114 def load_logger require_java time = Benchmark.realtime do puts 'adding log4j file ' + @log4j_xml_file org.apache.log4j.xml.DOMConfigurator.configure @log4j_xml_file end puts "Loaded log4j in #{time}s" end |
#parse_effective_pom ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/pom-loader.rb', line 99 def parse_effective_pom require_java time = Benchmark.realtime do pns = 'http://maven.apache.org/POM/4.0.0' pom_doc = Nokogiri::XML(File.open("#{@pom_dir}/target/effective-pom.xml")) pom_doc.xpath('//pom:systemProperty', 'pom' => pns).each do |n| name = n.xpath('pom:name', 'pom' => pns).first.text value = n.xpath('pom:value', 'pom' => pns).first.text puts "Adding System Property: #{name} value: #{value}" java.lang.System.setProperty name, value end end puts "Parsed effective-pom.xml in #{time}s" end |