pom-loader 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pom-loader (0.1.0)
5
+ nokogiri (~> 1.5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.4)
11
+ nokogiri (1.5.10-java)
12
+ rake (10.0.4)
13
+ rspec (2.13.0)
14
+ rspec-core (~> 2.13.0)
15
+ rspec-expectations (~> 2.13.0)
16
+ rspec-mocks (~> 2.13.0)
17
+ rspec-core (2.13.1)
18
+ rspec-expectations (2.13.0)
19
+ diff-lcs (>= 1.1.3, < 2.0)
20
+ rspec-mocks (2.13.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ bundler (~> 1.3.5)
28
+ pom-loader!
29
+ rake (~> 10.0.0)
30
+ rspec (~> 2.13.0)
data/LICENSE ADDED
@@ -0,0 +1,210 @@
1
+ Certain components of this software are provided or made available only
2
+ subject to the licenses under which such components were licensed to
3
+ HomeAway. The relevant components and corresponding licenses are listed
4
+ [in the folder in the distribution titled 'licenses']. In any event, the
5
+ disclaimer of warranty and limitation of liability provision in this
6
+ Agreement will apply to all Software in this distribution.
7
+
8
+
9
+ Apache License
10
+ Version 2.0, January 2004
11
+ http://www.apache.org/licenses/
12
+
13
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14
+
15
+ 1. Definitions.
16
+
17
+ "License" shall mean the terms and conditions for use, reproduction,
18
+ and distribution as defined by Sections 1 through 9 of this document.
19
+
20
+ "Licensor" shall mean the copyright owner or entity authorized by
21
+ the copyright owner that is granting the License.
22
+
23
+ "Legal Entity" shall mean the union of the acting entity and all
24
+ other entities that control, are controlled by, or are under common
25
+ control with that entity. For the purposes of this definition,
26
+ "control" means (i) the power, direct or indirect, to cause the
27
+ direction or management of such entity, whether by contract or
28
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
29
+ outstanding shares, or (iii) beneficial ownership of such entity.
30
+
31
+ "You" (or "Your") shall mean an individual or Legal Entity
32
+ exercising permissions granted by this License.
33
+
34
+ "Source" form shall mean the preferred form for making modifications,
35
+ including but not limited to software source code, documentation
36
+ source, and configuration files.
37
+
38
+ "Object" form shall mean any form resulting from mechanical
39
+ transformation or translation of a Source form, including but
40
+ not limited to compiled object code, generated documentation,
41
+ and conversions to other media types.
42
+
43
+ "Work" shall mean the work of authorship, whether in Source or
44
+ Object form, made available under the License, as indicated by a
45
+ copyright notice that is included in or attached to the work
46
+ (an example is provided in the Appendix below).
47
+
48
+ "Derivative Works" shall mean any work, whether in Source or Object
49
+ form, that is based on (or derived from) the Work and for which the
50
+ editorial revisions, annotations, elaborations, or other modifications
51
+ represent, as a whole, an original work of authorship. For the purposes
52
+ of this License, Derivative Works shall not include works that remain
53
+ separable from, or merely link (or bind by name) to the interfaces of,
54
+ the Work and Derivative Works thereof.
55
+
56
+ "Contribution" shall mean any work of authorship, including
57
+ the original version of the Work and any modifications or additions
58
+ to that Work or Derivative Works thereof, that is intentionally
59
+ submitted to Licensor for inclusion in the Work by the copyright owner
60
+ or by an individual or Legal Entity authorized to submit on behalf of
61
+ the copyright owner. For the purposes of this definition, "submitted"
62
+ means any form of electronic, verbal, or written communication sent
63
+ to the Licensor or its representatives, including but not limited to
64
+ communication on electronic mailing lists, source code control systems,
65
+ and issue tracking systems that are managed by, or on behalf of, the
66
+ Licensor for the purpose of discussing and improving the Work, but
67
+ excluding communication that is conspicuously marked or otherwise
68
+ designated in writing by the copyright owner as "Not a Contribution."
69
+
70
+ "Contributor" shall mean Licensor and any individual or Legal Entity
71
+ on behalf of whom a Contribution has been received by Licensor and
72
+ subsequently incorporated within the Work.
73
+
74
+ 2. Grant of Copyright License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ copyright license to reproduce, prepare Derivative Works of,
78
+ publicly display, publicly perform, sublicense, and distribute the
79
+ Work and such Derivative Works in Source or Object form.
80
+
81
+ 3. Grant of Patent License. Subject to the terms and conditions of
82
+ this License, each Contributor hereby grants to You a perpetual,
83
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
84
+ (except as stated in this section) patent license to make, have made,
85
+ use, offer to sell, sell, import, and otherwise transfer the Work,
86
+ where such license applies only to those patent claims licensable
87
+ by such Contributor that are necessarily infringed by their
88
+ Contribution(s) alone or by combination of their Contribution(s)
89
+ with the Work to which such Contribution(s) was submitted. If You
90
+ institute patent litigation against any entity (including a
91
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
92
+ or a Contribution incorporated within the Work constitutes direct
93
+ or contributory patent infringement, then any patent licenses
94
+ granted to You under this License for that Work shall terminate
95
+ as of the date such litigation is filed.
96
+
97
+ 4. Redistribution. You may reproduce and distribute copies of the
98
+ Work or Derivative Works thereof in any medium, with or without
99
+ modifications, and in Source or Object form, provided that You
100
+ meet the following conditions:
101
+
102
+ (a) You must give any other recipients of the Work or
103
+ Derivative Works a copy of this License; and
104
+
105
+ (b) You must cause any modified files to carry prominent notices
106
+ stating that You changed the files; and
107
+
108
+ (c) You must retain, in the Source form of any Derivative Works
109
+ that You distribute, all copyright, patent, trademark, and
110
+ attribution notices from the Source form of the Work,
111
+ excluding those notices that do not pertain to any part of
112
+ the Derivative Works; and
113
+
114
+ (d) If the Work includes a "NOTICE" text file as part of its
115
+ distribution, then any Derivative Works that You distribute must
116
+ include a readable copy of the attribution notices contained
117
+ within such NOTICE file, excluding those notices that do not
118
+ pertain to any part of the Derivative Works, in at least one
119
+ of the following places: within a NOTICE text file distributed
120
+ as part of the Derivative Works; within the Source form or
121
+ documentation, if provided along with the Derivative Works; or,
122
+ within a display generated by the Derivative Works, if and
123
+ wherever such third-party notices normally appear. The contents
124
+ of the NOTICE file are for informational purposes only and
125
+ do not modify the License. You may add Your own attribution
126
+ notices within Derivative Works that You distribute, alongside
127
+ or as an addendum to the NOTICE text from the Work, provided
128
+ that such additional attribution notices cannot be construed
129
+ as modifying the License.
130
+
131
+ You may add Your own copyright statement to Your modifications and
132
+ may provide additional or different license terms and conditions
133
+ for use, reproduction, or distribution of Your modifications, or
134
+ for any such Derivative Works as a whole, provided Your use,
135
+ reproduction, and distribution of the Work otherwise complies with
136
+ the conditions stated in this License.
137
+
138
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
139
+ any Contribution intentionally submitted for inclusion in the Work
140
+ by You to the Licensor shall be under the terms and conditions of
141
+ this License, without any additional terms or conditions.
142
+ Notwithstanding the above, nothing herein shall supersede or modify
143
+ the terms of any separate license agreement you may have executed
144
+ with Licensor regarding such Contributions.
145
+
146
+ 6. Trademarks. This License does not grant permission to use the trade
147
+ names, trademarks, service marks, or product names of the Licensor,
148
+ except as required for reasonable and customary use in describing the
149
+ origin of the Work and reproducing the content of the NOTICE file.
150
+
151
+ 7. Disclaimer of Warranty. Unless required by applicable law or
152
+ agreed to in writing, Licensor provides the Work (and each
153
+ Contributor provides its Contributions) on an "AS IS" BASIS,
154
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155
+ implied, including, without limitation, any warranties or conditions
156
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
157
+ PARTICULAR PURPOSE. You are solely responsible for determining the
158
+ appropriateness of using or redistributing the Work and assume any
159
+ risks associated with Your exercise of permissions under this License.
160
+
161
+ 8. Limitation of Liability. In no event and under no legal theory,
162
+ whether in tort (including negligence), contract, or otherwise,
163
+ unless required by applicable law (such as deliberate and grossly
164
+ negligent acts) or agreed to in writing, shall any Contributor be
165
+ liable to You for damages, including any direct, indirect, special,
166
+ incidental, or consequential damages of any character arising as a
167
+ result of this License or out of the use or inability to use the
168
+ Work (including but not limited to damages for loss of goodwill,
169
+ work stoppage, computer failure or malfunction, or any and all
170
+ other commercial damages or losses), even if such Contributor
171
+ has been advised of the possibility of such damages.
172
+
173
+ 9. Accepting Warranty or Additional Liability. While redistributing
174
+ the Work or Derivative Works thereof, You may choose to offer,
175
+ and charge a fee for, acceptance of support, warranty, indemnity,
176
+ or other liability obligations and/or rights consistent with this
177
+ License. However, in accepting such obligations, You may act only
178
+ on Your own behalf and on Your sole responsibility, not on behalf
179
+ of any other Contributor, and only if You agree to indemnify,
180
+ defend, and hold each Contributor harmless for any liability
181
+ incurred by, or claims asserted against, such Contributor by reason
182
+ of your accepting any such warranty or additional liability.
183
+
184
+ END OF TERMS AND CONDITIONS
185
+
186
+ APPENDIX: How to apply the Apache License to your work.
187
+
188
+ To apply the Apache License to your work, attach the following
189
+ boilerplate notice, with the fields enclosed by brackets "[]"
190
+ replaced with your own identifying information. (Don't include
191
+ the brackets!) The text should be enclosed in the appropriate
192
+ comment syntax for the file format. We also recommend that a
193
+ file or class name and description of purpose be included on the
194
+ same "printed page" as the copyright notice for easier
195
+ identification within third-party archives.
196
+
197
+ Copyright 2013 HomeAway
198
+
199
+ Licensed under the Apache License, Version 2.0 (the "License");
200
+ you may not use this file except in compliance with the License.
201
+ You may obtain a copy of the License at
202
+
203
+ http://www.apache.org/licenses/LICENSE-2.0
204
+
205
+ Unless required by applicable law or agreed to in writing, software
206
+ distributed under the License is distributed on an "AS IS" BASIS,
207
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208
+ See the License for the specific language governing permissions and
209
+ limitations under the License.
210
+
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ PomLoader - A Maven Pom Loader
2
+ ==============================
3
+
4
+ Simplify working with java dependencies.
5
+
6
+ You need to meet the following requirements:
7
+ 1. Running with jruby
8
+ 2. Mavenized Project
9
+
10
+ ## HOWTO
11
+ - Specify your java dependencies in a pom.xml (same as you would a java
12
+ maven project)
13
+ - Add the following lines to an intializer or spec_helper
14
+ - Smile because your java dependencies are loaded onto your classpath
15
+ when you start your app
16
+
17
+ ```ruby
18
+ require 'pom-loader'
19
+ pom_dir = File.expand_path("../../", __FILE__)
20
+ mvn = ENV['MVN2_EXE'] || 'mvn'
21
+ PomLoader.load(pom_dir: pom_dir, mvn_exe: mvn)
22
+ $! = nil # unset evil magic bit
23
+ ```
24
+
25
+ --
26
+ PomLoader will cause the ruby process to:
27
+ 1. parse the pom.xml file
28
+ 2. figure out and load all jar dependencies.
29
+ 3. Setup the log4j context if target/classes/com/homeaway/log4j.xml exists
30
+ 4. Setup Java system properties for every property parsed from the jetty plugin system properties.
31
+
32
+ ## Adding the Rake Task
33
+ We've provided a rake task that will gather/install all of your java dependencies for your jruby project.
34
+ Inside of your project's rakefile simply add:
35
+
36
+ ```ruby
37
+ require 'pom-loader/tasks'
38
+ ```
39
+
40
+ And now when you 'rake -T' you should see:
41
+ ```
42
+ ...
43
+ rake pom_loader:load # Generate and gather all of the files required for PomLoader
44
+ ...
45
+ ```
46
+ ## License
47
+
48
+ Apache License version 2.0
49
+
50
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ require 'bundler/gem_tasks'
3
+ require 'pom-loader/tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2013 HomeAway, Inc.
2
+ # All rights reserved. http://www.homeaway.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Modeled after the bundler gem_tasks gem_helper class.
17
+ # Now all that's required is a: require 'pom-loader/tasks' to bring in the tasks.
18
+ require 'pom-loader'
19
+
20
+ module PomLoader
21
+ class Tasks
22
+ include Rake::DSL if defined? Rake::DSL
23
+
24
+ class << self
25
+ def install_tasks(opts = {})
26
+ new.install
27
+ end
28
+ end
29
+
30
+ def install
31
+ desc 'Generate and gather all of the files required for PomLoader'
32
+ namespace :pom_loader do
33
+ task :load do |t|
34
+ PomLoader.load
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ PomLoader::Tasks.install_tasks
@@ -0,0 +1,3 @@
1
+ module PomLoader
2
+ VERSION = '0.1.0'
3
+ end
data/lib/pom-loader.rb ADDED
@@ -0,0 +1,130 @@
1
+ # Copyright (c) 2013 HomeAway, Inc.
2
+ # All rights reserved. http://www.homeaway.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ require 'benchmark'
18
+ require 'nokogiri'
19
+
20
+ module PomLoader
21
+
22
+ def self.load(options = {})
23
+ loader = PomLoader::Loader.new(options)
24
+ loader.load
25
+ end
26
+
27
+ class Loader
28
+ attr_accessor :pom_dir, :mvn_repo_dir, :target_classes_dir, :log4j_xml_file, :mvn_exe, :loaded, :pom_changed_at
29
+
30
+ # @param [Hash] options overrides default mvn pom settings
31
+ # @option options [String] :pom_dir (Dir.pwd) The directory where your pom.xml file lives
32
+ # @option options [String] :mvn_repo_dir (Dir.home + '/.m2/repository') The directory where your .m2 repository lives
33
+ # @option options [String] :target_classes_dir (pom_dir + '/target/classes') The target classes directory
34
+ # @option options [String] :log4j_xml_file ('') Optional log4j configuration
35
+ # @option options [String] :mvn_exe ('mvn') the maven executable command
36
+ #
37
+ # note: mvn_repo_dir has absolutely no impact on anything.
38
+ def initialize(options = {})
39
+ @pom_dir = options[:pom_dir] || Dir.pwd
40
+ @mvn_repo_dir = options[:mvn_repo_dir] || (Dir.home + '/.m2/repository')
41
+ @target_classes_dir = options[:target_classes_dir] || (@pom_dir + '/target/classes')
42
+ @log4j_xml_file = options[:log4j_xml_file] || "#{@target_classes_dir}/com/homeaway/log4j.xml"
43
+ @mvn_exe = options[:mvn_exe] || ENV['MVN2_EXE'] || 'mvn'
44
+ end
45
+
46
+ # Load dependency jars onto classpath specified by a maven pom.xml file
47
+ def load
48
+ if File.exists? "#{pom_dir}/pom.xml"
49
+ @pom_changed_at = File.ctime("#{pom_dir}/pom.xml")
50
+ puts "Loading java environment from #{@pom_dir}/pom.xml"
51
+ build_effective_pom
52
+ build_classpath
53
+ add_jars_to_classpath
54
+ parse_effective_pom
55
+ load_logger if File.exists? @log4j_xml_file
56
+ @loaded = true
57
+ else
58
+ @loaded = false
59
+ puts "Not loading java environment. pom dir=#{@pom_dir}"
60
+ end
61
+ self
62
+ end
63
+
64
+ def build_effective_pom
65
+ time = Benchmark.realtime do
66
+ effective_pom_path = "#{@pom_dir}/target/effective-pom.xml"
67
+ if !File.exists?(effective_pom_path) || File.ctime(effective_pom_path) < @pom_changed_at
68
+ process_output = `#{mvn_exe} -f #{@pom_dir}/pom.xml help:effective-pom -Doutput=#{effective_pom_path}`
69
+ puts process_output unless $?.success?
70
+ end
71
+ end
72
+ puts "Built effective-pom.xml in #{time}s"
73
+ end
74
+
75
+ def build_classpath
76
+ time = Benchmark.realtime do
77
+ build_classpath = "#{@pom_dir}/target/build-classpath.txt"
78
+ if !File.exists?(build_classpath) || File.ctime(build_classpath) < @pom_changed_at
79
+ process_output = `#{@mvn_exe} -f #{@pom_dir}/pom.xml dependency:build-classpath -DincludeTypes=jar -Dmdep.outputFile=#{build_classpath}`
80
+ puts process_output unless $?.success?
81
+ end
82
+ end
83
+ puts "Built build-classpath.txt in #{time}s"
84
+ end
85
+
86
+ def add_jars_to_classpath
87
+ time = Benchmark.realtime do
88
+ File.readlines("#{@pom_dir}/target/build-classpath.txt").each do |line|
89
+ line.split(':').each do |jar|
90
+ $CLASSPATH << jar
91
+ end
92
+ end
93
+
94
+ $CLASSPATH << @target_classes_dir if Dir.exists? @target_classes_dir
95
+ end
96
+ puts "Added java paths to $CLASSPATH in #{time}"
97
+ end
98
+
99
+ def parse_effective_pom
100
+ require_java
101
+ time = Benchmark.realtime do
102
+ pns = 'http://maven.apache.org/POM/4.0.0'
103
+ pom_doc = Nokogiri::XML(File.open("#{@pom_dir}/target/effective-pom.xml"))
104
+ pom_doc.xpath('//pom:systemProperty', 'pom' => pns).each do |n|
105
+ name = n.xpath('pom:name', 'pom' => pns).first.text
106
+ value = n.xpath('pom:value', 'pom' => pns).first.text
107
+ puts "Adding System Property: #{name} value: #{value}"
108
+ java.lang.System.setProperty name, value
109
+ end
110
+ end
111
+ puts "Parsed effective-pom.xml in #{time}s"
112
+ end
113
+
114
+ def load_logger
115
+ require_java
116
+ time = Benchmark.realtime do
117
+ puts 'adding log4j file ' + @log4j_xml_file
118
+ org.apache.log4j.xml.DOMConfigurator.configure @log4j_xml_file
119
+ end
120
+ puts "Loaded log4j in #{time}s"
121
+ end
122
+
123
+ private
124
+
125
+ def require_java
126
+ raise 'Sorry you do not seem to be running on java so I cannot proceed.' unless RUBY_PLATFORM == 'java'
127
+ require 'java'
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe PomLoader::Loader do
4
+
5
+ before(:each) { @pom_dir = File.expand_path('../../test-poms', __FILE__) }
6
+ after(:each) { FileUtils.rm_rf("#{@pom_dir}/target", secure: true) }
7
+
8
+ it 'should be able to be initialized with defaults' do
9
+ expect{ PomLoader::Loader.new }.to_not raise_error
10
+ end
11
+
12
+ it 'should be able to be initialized with options' do
13
+ loader = PomLoader::Loader.new(pom_dir: 'pom', mvn_repo_dir: 'repo', target_classes_dir: 'target', log4j_xml_file: 'log4j', mvn_exe: 'exe')
14
+ loader.pom_dir.should eql 'pom'
15
+ loader.mvn_repo_dir.should eql 'repo'
16
+ loader.target_classes_dir.should eql 'target'
17
+ loader.log4j_xml_file.should eql 'log4j'
18
+ loader.mvn_exe.should eql 'exe'
19
+ end
20
+
21
+ it 'should be able to be able to build an effective pom' do
22
+ loader = PomLoader::Loader.new(pom_dir: @pom_dir)
23
+ loader.pom_dir.should end_with 'spec/test-poms'
24
+ loader.build_effective_pom
25
+
26
+ File.exist?("#{@pom_dir}/target/effective-pom.xml").should be_true
27
+
28
+ effective_pom = Nokogiri::XML(File.open("#{@pom_dir}/target/effective-pom.xml"))
29
+ effective_pom.css('project name').count.should eql 1
30
+
31
+ # Doesn't work off the bat :(
32
+ #expected_pom = Nokogiri::XML(File.open("#{@pom_dir}/expected-pom.xml"))
33
+ #effective_pom.should eql expected_pom
34
+ end
35
+
36
+ it 'should be able to build a class path and download all of our jars' do
37
+ loader = PomLoader::Loader.new(pom_dir: @pom_dir)
38
+ loader.pom_dir.should end_with 'spec/test-poms'
39
+ FileUtils.rm_rf("#{@pom_dir}/target", secure: true)
40
+ FileUtils.rm_rf(loader.mvn_repo_dir, secure: true)
41
+ loader.build_classpath
42
+
43
+ File.exist?("#{@pom_dir}/target/build-classpath.txt").should be_true
44
+
45
+ jar_count = 0
46
+ File.readlines("#{@pom_dir}/target/build-classpath.txt").each do |line|
47
+ line.split(':').each do |jar|
48
+ File.exists?(jar).should be_true
49
+ jar_count += 1
50
+ end
51
+ end
52
+
53
+ jar_count.should eql 1
54
+ end
55
+
56
+
57
+ it 'should add jars to the class path' do
58
+ loader = PomLoader::Loader.new(pom_dir: @pom_dir)
59
+ loader.pom_dir.should end_with 'spec/test-poms'
60
+ loader.build_classpath
61
+ loader.add_jars_to_classpath
62
+
63
+ $CLASSPATH.count.should eql 7 # may change based on local config
64
+ end
65
+
66
+ it 'should parse the effective pom' do
67
+ loader = PomLoader::Loader.new(pom_dir: @pom_dir)
68
+ loader.pom_dir.should end_with 'spec/test-poms'
69
+ loader.build_effective_pom
70
+ loader.build_classpath
71
+ loader.add_jars_to_classpath
72
+ loader.parse_effective_pom
73
+
74
+ # TODO: This pom doesn't have any systemProperty tags so this is a useless test
75
+ # java.lang.System.getProperties.count.should eql 63
76
+ end
77
+
78
+ it 'should be able to load everything in one command' do
79
+ loader = PomLoader::Loader.new(pom_dir: @pom_dir)
80
+ loader.pom_dir.should end_with 'spec/test-poms'
81
+ loader.load
82
+
83
+ # Verify the loader is initialized
84
+ loader.pom_dir.should_not be_nil
85
+ loader.mvn_repo_dir.should_not be_nil
86
+ loader.target_classes_dir.should_not be_nil
87
+ loader.log4j_xml_file.should_not be_nil
88
+ loader.mvn_exe.should_not be_nil
89
+
90
+
91
+ # Verify we have an effective pom
92
+ effective_pom = Nokogiri::XML(File.open("#{@pom_dir}/target/effective-pom.xml"))
93
+ effective_pom.css('project name').count.should eql 1
94
+
95
+ # Verify our build-classpath file is correct and our jars exist
96
+ jar_count = 0
97
+ File.readlines("#{@pom_dir}/target/build-classpath.txt").each do |line|
98
+ line.split(':').each do |jar|
99
+ File.exists?(jar).should be_true
100
+ jar_count += 1
101
+ end
102
+ end
103
+ jar_count.should eql 1
104
+
105
+ # Verify our classpath has been modified.
106
+ $CLASSPATH.count.should eql 7
107
+
108
+ # Verify our systemProperties have been added.
109
+ # java.lang.System.getProperties.count.should eql 63
110
+ end
111
+ end
112
+
@@ -0,0 +1,49 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe PomLoader do
4
+ specify { subject.should respond_to(:load) }
5
+
6
+ it 'should load using specific fields' do
7
+ loader = PomLoader.load(pom_dir: 'pom', mvn_repo_dir: 'repo', target_classes_dir: 'target', log4j_xml_file: 'log4j', mvn_exe: 'exe')
8
+ loader.pom_dir.should eql 'pom'
9
+ loader.mvn_repo_dir.should eql 'repo'
10
+ loader.target_classes_dir.should eql 'target'
11
+ loader.log4j_xml_file.should eql 'log4j'
12
+ loader.mvn_exe.should eql 'exe'
13
+ end
14
+
15
+
16
+ it 'should be able to load a real project' do
17
+ pom_dir = File.expand_path('../../test-poms', __FILE__)
18
+ loader = PomLoader::load(pom_dir: pom_dir)
19
+ loader.pom_dir.should end_with 'spec/test-poms'
20
+
21
+ # Verify the loader is initialized
22
+ loader.pom_dir.should_not be_nil
23
+ loader.mvn_repo_dir.should_not be_nil
24
+ loader.target_classes_dir.should_not be_nil
25
+ loader.log4j_xml_file.should_not be_nil
26
+ loader.mvn_exe.should_not be_nil
27
+
28
+
29
+ # Verify we have an effective pom
30
+ effective_pom = Nokogiri::XML(File.open("#{pom_dir}/target/effective-pom.xml"))
31
+ effective_pom.css('project name').count.should eql 1
32
+
33
+ # Verify our build-classpath file is correct and our jars exist
34
+ jar_count = 0
35
+ File.readlines("#{pom_dir}/target/build-classpath.txt").each do |line|
36
+ line.split(':').each do |jar|
37
+ File.exists?(jar).should be_true
38
+ jar_count += 1
39
+ end
40
+ end
41
+ jar_count.should eql 1
42
+
43
+ # Verify our classpath has been modified.
44
+ $CLASSPATH.count.should eql 7
45
+
46
+ # Verify our systemProperties have been added.
47
+ # java.lang.System.getProperties.count.should eql 63
48
+ end
49
+ end
@@ -0,0 +1 @@
1
+ require 'pom-loader'
@@ -0,0 +1,157 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- ====================================================================== -->
3
+ <!-- -->
4
+ <!-- Generated by Maven Help Plugin on 2013-08-23T11:26:31 -->
5
+ <!-- See: http://maven.apache.org/plugins/maven-help-plugin/ -->
6
+ <!-- -->
7
+ <!-- ====================================================================== -->
8
+
9
+ <!-- ====================================================================== -->
10
+ <!-- -->
11
+ <!-- Effective POM for project 'com.mycompany.app:my-app:jar:1.0-SNAPSHOT' -->
12
+ <!-- -->
13
+ <!-- ====================================================================== -->
14
+
15
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
16
+ <modelVersion>4.0.0</modelVersion>
17
+ <groupId>com.mycompany.app</groupId>
18
+ <artifactId>my-app</artifactId>
19
+ <version>1.0-SNAPSHOT</version>
20
+ <name>Maven Quick Start Archetype</name>
21
+ <url>http://maven.apache.org</url>
22
+ <build>
23
+ <sourceDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/src/main/java</sourceDirectory>
24
+ <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
25
+ <testSourceDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/src/test/java</testSourceDirectory>
26
+ <outputDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/target/classes</outputDirectory>
27
+ <testOutputDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/target/test-classes</testOutputDirectory>
28
+ <resources>
29
+ <resource>
30
+ <mergeId>resource-0</mergeId>
31
+ <directory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/src/main/resources</directory>
32
+ </resource>
33
+ </resources>
34
+ <testResources>
35
+ <testResource>
36
+ <mergeId>resource-1</mergeId>
37
+ <directory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/src/test/resources</directory>
38
+ </testResource>
39
+ </testResources>
40
+ <directory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/target</directory>
41
+ <finalName>my-app-1.0-SNAPSHOT</finalName>
42
+ <pluginManagement>
43
+ <plugins>
44
+ <plugin>
45
+ <artifactId>maven-antrun-plugin</artifactId>
46
+ <version>1.3</version>
47
+ </plugin>
48
+ <plugin>
49
+ <artifactId>maven-assembly-plugin</artifactId>
50
+ <version>2.2-beta-2</version>
51
+ </plugin>
52
+ <plugin>
53
+ <artifactId>maven-clean-plugin</artifactId>
54
+ <version>2.2</version>
55
+ </plugin>
56
+ <plugin>
57
+ <artifactId>maven-compiler-plugin</artifactId>
58
+ <version>2.0.2</version>
59
+ </plugin>
60
+ <plugin>
61
+ <artifactId>maven-dependency-plugin</artifactId>
62
+ <version>2.0</version>
63
+ </plugin>
64
+ <plugin>
65
+ <artifactId>maven-deploy-plugin</artifactId>
66
+ <version>2.4</version>
67
+ </plugin>
68
+ <plugin>
69
+ <artifactId>maven-ear-plugin</artifactId>
70
+ <version>2.3.1</version>
71
+ </plugin>
72
+ <plugin>
73
+ <artifactId>maven-ejb-plugin</artifactId>
74
+ <version>2.1</version>
75
+ </plugin>
76
+ <plugin>
77
+ <artifactId>maven-install-plugin</artifactId>
78
+ <version>2.2</version>
79
+ </plugin>
80
+ <plugin>
81
+ <artifactId>maven-jar-plugin</artifactId>
82
+ <version>2.2</version>
83
+ </plugin>
84
+ <plugin>
85
+ <artifactId>maven-javadoc-plugin</artifactId>
86
+ <version>2.5</version>
87
+ </plugin>
88
+ <plugin>
89
+ <artifactId>maven-plugin-plugin</artifactId>
90
+ <version>2.4.3</version>
91
+ </plugin>
92
+ <plugin>
93
+ <artifactId>maven-rar-plugin</artifactId>
94
+ <version>2.2</version>
95
+ </plugin>
96
+ <plugin>
97
+ <artifactId>maven-release-plugin</artifactId>
98
+ <version>2.0-beta-8</version>
99
+ </plugin>
100
+ <plugin>
101
+ <artifactId>maven-resources-plugin</artifactId>
102
+ <version>2.3</version>
103
+ </plugin>
104
+ <plugin>
105
+ <artifactId>maven-site-plugin</artifactId>
106
+ <version>2.0-beta-7</version>
107
+ </plugin>
108
+ <plugin>
109
+ <artifactId>maven-source-plugin</artifactId>
110
+ <version>2.0.4</version>
111
+ </plugin>
112
+ <plugin>
113
+ <artifactId>maven-surefire-plugin</artifactId>
114
+ <version>2.4.3</version>
115
+ </plugin>
116
+ <plugin>
117
+ <artifactId>maven-war-plugin</artifactId>
118
+ <version>2.1-alpha-2</version>
119
+ </plugin>
120
+ </plugins>
121
+ </pluginManagement>
122
+ <plugins>
123
+ <plugin>
124
+ <artifactId>maven-help-plugin</artifactId>
125
+ <version>2.2.1-SNAPSHOT</version>
126
+ </plugin>
127
+ </plugins>
128
+ </build>
129
+ <repositories>
130
+ <repository>
131
+ <releases />
132
+ <snapshots />
133
+ <id>central</id>
134
+ <url>http://central</url>
135
+ </repository>
136
+ </repositories>
137
+ <pluginRepositories>
138
+ <pluginRepository>
139
+ <releases />
140
+ <snapshots />
141
+ <id>central</id>
142
+ <url>http://central</url>
143
+ </pluginRepository>
144
+ </pluginRepositories>
145
+ <dependencies>
146
+ <dependency>
147
+ <groupId>junit</groupId>
148
+ <artifactId>junit</artifactId>
149
+ <version>3.8.1</version>
150
+ <scope>test</scope>
151
+ </dependency>
152
+ </dependencies>
153
+ <reporting>
154
+ <outputDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/target/site</outputDirectory>
155
+ </reporting>
156
+ </project>
157
+
@@ -0,0 +1,20 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
2
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+ <modelVersion>4.0.0</modelVersion>
6
+ <groupId>com.mycompany.app</groupId>
7
+ <artifactId>my-app</artifactId>
8
+ <packaging>jar</packaging>
9
+ <version>1.0-SNAPSHOT</version>
10
+ <name>Maven Quick Start Archetype</name>
11
+ <url>http://maven.apache.org</url>
12
+ <dependencies>
13
+ <dependency>
14
+ <groupId>junit</groupId>
15
+ <artifactId>junit</artifactId>
16
+ <version>3.8.1</version>
17
+ <scope>test</scope>
18
+ </dependency>
19
+ </dependencies>
20
+ </project>
@@ -0,0 +1 @@
1
+ /Users/mmay/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
@@ -0,0 +1,156 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- ====================================================================== -->
3
+ <!-- -->
4
+ <!-- Generated by Maven Help Plugin on 2013-08-23T11:57:04 -->
5
+ <!-- See: http://maven.apache.org/plugins/maven-help-plugin/ -->
6
+ <!-- -->
7
+ <!-- ====================================================================== -->
8
+
9
+ <!-- ====================================================================== -->
10
+ <!-- -->
11
+ <!-- Effective POM for project 'com.mycompany.app:my-app:jar:1.0-SNAPSHOT' -->
12
+ <!-- -->
13
+ <!-- ====================================================================== -->
14
+
15
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
16
+ <modelVersion>4.0.0</modelVersion>
17
+ <groupId>com.mycompany.app</groupId>
18
+ <artifactId>my-app</artifactId>
19
+ <version>1.0-SNAPSHOT</version>
20
+ <name>Maven Quick Start Archetype</name>
21
+ <url>http://maven.apache.org</url>
22
+ <build>
23
+ <sourceDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/src/main/java</sourceDirectory>
24
+ <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
25
+ <testSourceDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/src/test/java</testSourceDirectory>
26
+ <outputDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/target/classes</outputDirectory>
27
+ <testOutputDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/target/test-classes</testOutputDirectory>
28
+ <resources>
29
+ <resource>
30
+ <mergeId>resource-0</mergeId>
31
+ <directory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/src/main/resources</directory>
32
+ </resource>
33
+ </resources>
34
+ <testResources>
35
+ <testResource>
36
+ <mergeId>resource-1</mergeId>
37
+ <directory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/src/test/resources</directory>
38
+ </testResource>
39
+ </testResources>
40
+ <directory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/target</directory>
41
+ <finalName>my-app-1.0-SNAPSHOT</finalName>
42
+ <pluginManagement>
43
+ <plugins>
44
+ <plugin>
45
+ <artifactId>maven-antrun-plugin</artifactId>
46
+ <version>1.3</version>
47
+ </plugin>
48
+ <plugin>
49
+ <artifactId>maven-assembly-plugin</artifactId>
50
+ <version>2.2-beta-2</version>
51
+ </plugin>
52
+ <plugin>
53
+ <artifactId>maven-clean-plugin</artifactId>
54
+ <version>2.2</version>
55
+ </plugin>
56
+ <plugin>
57
+ <artifactId>maven-compiler-plugin</artifactId>
58
+ <version>2.0.2</version>
59
+ </plugin>
60
+ <plugin>
61
+ <artifactId>maven-dependency-plugin</artifactId>
62
+ <version>2.0</version>
63
+ </plugin>
64
+ <plugin>
65
+ <artifactId>maven-deploy-plugin</artifactId>
66
+ <version>2.4</version>
67
+ </plugin>
68
+ <plugin>
69
+ <artifactId>maven-ear-plugin</artifactId>
70
+ <version>2.3.1</version>
71
+ </plugin>
72
+ <plugin>
73
+ <artifactId>maven-ejb-plugin</artifactId>
74
+ <version>2.1</version>
75
+ </plugin>
76
+ <plugin>
77
+ <artifactId>maven-install-plugin</artifactId>
78
+ <version>2.2</version>
79
+ </plugin>
80
+ <plugin>
81
+ <artifactId>maven-jar-plugin</artifactId>
82
+ <version>2.2</version>
83
+ </plugin>
84
+ <plugin>
85
+ <artifactId>maven-javadoc-plugin</artifactId>
86
+ <version>2.5</version>
87
+ </plugin>
88
+ <plugin>
89
+ <artifactId>maven-plugin-plugin</artifactId>
90
+ <version>2.4.3</version>
91
+ </plugin>
92
+ <plugin>
93
+ <artifactId>maven-rar-plugin</artifactId>
94
+ <version>2.2</version>
95
+ </plugin>
96
+ <plugin>
97
+ <artifactId>maven-release-plugin</artifactId>
98
+ <version>2.0-beta-8</version>
99
+ </plugin>
100
+ <plugin>
101
+ <artifactId>maven-resources-plugin</artifactId>
102
+ <version>2.3</version>
103
+ </plugin>
104
+ <plugin>
105
+ <artifactId>maven-site-plugin</artifactId>
106
+ <version>2.0-beta-7</version>
107
+ </plugin>
108
+ <plugin>
109
+ <artifactId>maven-source-plugin</artifactId>
110
+ <version>2.0.4</version>
111
+ </plugin>
112
+ <plugin>
113
+ <artifactId>maven-surefire-plugin</artifactId>
114
+ <version>2.4.3</version>
115
+ </plugin>
116
+ <plugin>
117
+ <artifactId>maven-war-plugin</artifactId>
118
+ <version>2.1-alpha-2</version>
119
+ </plugin>
120
+ </plugins>
121
+ </pluginManagement>
122
+ <plugins>
123
+ <plugin>
124
+ <artifactId>maven-help-plugin</artifactId>
125
+ <version>2.2.1-SNAPSHOT</version>
126
+ </plugin>
127
+ </plugins>
128
+ </build>
129
+ <repositories>
130
+ <repository>
131
+ <releases />
132
+ <snapshots />
133
+ <id>central</id>
134
+ <url>http://central</url>
135
+ </repository>
136
+ </repositories>
137
+ <pluginRepositories>
138
+ <pluginRepository>
139
+ <releases />
140
+ <snapshots />
141
+ <id>central</id>
142
+ <url>http://central</url>
143
+ </pluginRepository>
144
+ </pluginRepositories>
145
+ <dependencies>
146
+ <dependency>
147
+ <groupId>junit</groupId>
148
+ <artifactId>junit</artifactId>
149
+ <version>3.8.1</version>
150
+ <scope>test</scope>
151
+ </dependency>
152
+ </dependencies>
153
+ <reporting>
154
+ <outputDirectory>/Users/mmay/dev/homeaway/pom-loader/spec/test-poms/target/site</outputDirectory>
155
+ </reporting>
156
+ </project>
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pom-loader
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Matt Kinman
9
+ - Patrick Ritchie
10
+ - Michael May
11
+ - Alan Scherger
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2013-08-23 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: nokogiri
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.5.0
24
+ none: false
25
+ requirement: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.5.0
30
+ none: false
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 10.0.0
40
+ none: false
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.0
46
+ none: false
47
+ prerelease: false
48
+ type: :development
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.3.5
56
+ none: false
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.5
62
+ none: false
63
+ prerelease: false
64
+ type: :development
65
+ - !ruby/object:Gem::Dependency
66
+ name: rspec
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ version: 2.13.0
72
+ none: false
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.13.0
78
+ none: false
79
+ prerelease: false
80
+ type: :development
81
+ description: Can interpret a maven pom and pull properties and classes into context.
82
+ email: mmay@homeaway.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files:
86
+ - README.md
87
+ files:
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE
91
+ - Rakefile
92
+ - README.md
93
+ - lib/pom-loader.rb
94
+ - lib/pom-loader/tasks.rb
95
+ - lib/pom-loader/version.rb
96
+ - spec/spec_helper.rb
97
+ - spec/pom-loader/loader_spec.rb
98
+ - spec/pom-loader/pom-loader_spec.rb
99
+ - spec/test-poms/effective-pom.xml
100
+ - spec/test-poms/pom.xml
101
+ - spec/test-poms/target/build-classpath.txt
102
+ - spec/test-poms/target/effective-pom.xml
103
+ homepage: http://github.com/homeaway/pom-loader
104
+ licenses: []
105
+ post_install_message:
106
+ rdoc_options:
107
+ - --charset=UTF-8
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ segments:
115
+ - 0
116
+ hash: 2
117
+ version: '0'
118
+ none: false
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: 1.3.0
124
+ none: false
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.24
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: pom-loader - Loads maven poms into ruby context
131
+ test_files:
132
+ - spec/pom-loader/loader_spec.rb
133
+ - spec/pom-loader/pom-loader_spec.rb