Class: Maven::Tools::POM
- Inherits:
-
Object
show all
- Includes:
- DSL
- Defined in:
- lib/maven/tools/pom.rb
Instance Method Summary
collapse
Methods included from DSL
#_dependency, #_dependency!, #_dependency?, #activation, #add_execute_task, #archives, #args_and_options, #artifact, #basedir, #build, #ci_management, #configuration, #contributor, #current, #dependency, #dependency_container, #dependency_set, #developer, #directory, #distribution, #distribution_management, #do_dependency, #do_gem, #do_jruby_plugin, #enabled, #eval_pom, #excludes, #exclusion, #execute, #execute_goal, #execute_goals, #extension, #file, #fill, #fill_options, #final_name, #find_dependency, #gem, #gem!, #gem?, #gemfile, #gemspec, #gemspec_without_gem_dependencies?, #git, #group, #id, #includes, #inherit, #issue_management, #jar!, #jarfile, #jruby_plugin, #jruby_plugin!, #license, #licenses, #local, #mailing_list, #maven, #method_missing, #model, #needs_torquebox=, #notifier, #organization, #other_archives, #output_directory, #overrides, #packaging, #path, #phase, #platforms, #plugin, #plugin!, #plugin_repository, #prepare_config, #prerequisites, #profile, #profile!, #project, #properties, #property, #releases, #relocation, #report_set, #reporting, #repository, #repository_policy, #resource, #retrieve_dependency, #roles, #ruby, #scope, #set_config, #setup_jruby_plugins_version, #site, #snapshot_repository, #snapshots, #source, #source_control, #system, #tesla, #test_resource, #use, #xml
Constructor Details
#initialize(file = nil, snapshot = false) ⇒ POM
Returns a new instance of POM.
61
62
63
64
65
66
67
|
# File 'lib/maven/tools/pom.rb', line 61
def initialize( file = nil, snapshot = false )
if file.is_a? Gem::Specification
eval_spec( file, snapshot )
else
eval_file( file )
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Maven::Tools::DSL
Instance Method Details
#eval_file(file) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/maven/tools/pom.rb', line 38
def eval_file( file )
if file && ::File.directory?( file )
dir = file
file = nil
else
dir = '.'
end
unless file
file = pom_file( 'pom.rb', dir )
file ||= pom_file( 'Mavenfile', dir )
file ||= pom_file( 'Gemfile', dir )
file ||= pom_file( '*.gemspec', dir )
end
if file
FileUtils.cd( dir ) do
@model = to_model( ::File.basename( file ) )
end
end
end
|
#eval_spec(s, snapshot) ⇒ Object
32
33
34
35
36
|
# File 'lib/maven/tools/pom.rb', line 32
def eval_spec( s, snapshot )
@model = tesla do
gemspec s, :snapshot => snapshot, :no_rubygems_repo => true
end
end
|
#pom_file(pom, dir = '.') ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/maven/tools/pom.rb', line 69
def pom_file( pom, dir = '.' )
files = Dir[ ::File.join( dir, pom ) ]
case files.size
when 0
when 1
files.first
else
warn 'more than one pom file found'
end
end
|
#to_file(file) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/maven/tools/pom.rb', line 89
def to_file( file )
if @model
v = ::Maven::Tools::Visitor.new( ::File.open( file, 'w' ) )
v.accept_project( @model )
true
end
end
|
#to_model(file) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/maven/tools/pom.rb', line 97
def to_model( file )
if ::File.exists?( file )
case file
when /pom.rb/
eval_pom( "tesla do\n#{ ::File.read( file ) }\nend", file )
when /(Maven|Gem|Jar)file/
eval_pom( "tesla do\n#{ ::File.read( file ) }\nend", file )
when /.+\.gemspec/
eval_pom( "tesla do\ngemspec( '#{ ::File.basename( file ) }' )\nend", file )
end
else
eval_pom( "tesla do\n#{file}\nend", nil )
end
rescue ArgumentError => e
warn 'fallback to old maven model'
puts e.message
puts e.backtrace.join("\n\t")
raise 'TODO old maven model'
end
|
#to_s ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/maven/tools/pom.rb', line 80
def to_s
if @model
io = String.new
v = ::Maven::Tools::Visitor.new( io )
v.accept_project( @model )
io
end
end
|