Class: Maven::Tools::POM

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/maven/tools/pom.rb

Instance Method Summary collapse

Methods included from DSL

#activation, #add_execute_task, #archives, #args_and_options, #artifact, #basedir, #build, #contributor, #dependency, #dependency!, #dependency?, #dependency_container, #dependency_set, #developer, #distribution, #do_dependency, #do_gem, #eval_pom, #excludes, #execute, #execute_goal, #execute_goals, #extension, #file, #fill, #fill_options, #find_dependency, #gem, #gem!, #gem?, #gemfile, #gemspec, #git, #group, #id, #includes, #inherit, #issue_management, #jar!, #jarfile, #jruby_plugin, #license, #local, #mailing_list, #maven, #method_missing, #model, #organization, #other_archives, #overrides, #path, #phase, #platforms, #plugin, #plugin!, #plugin_repository, #prerequisites, #profile, #project, #properties, #property, #releases, #report_set, #reporting, #repository, #resource, #respository_policy, #retrieve_dependency, #roles, #ruby, #scope, #set_config, #setup_jruby_plugins_version, #site, #snapshot_repository, #snapshots, #source, #source_control, #tesla, #test_resource, #xml

Constructor Details

#initialize(file = nil) ⇒ POM

Returns a new instance of POM.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/maven/tools/pom.rb', line 33

def initialize( file = nil )
  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( 'Jarfile', dir )
    file ||= pom_file( '*.gemspec', dir )
  end

  FileUtils.cd( dir ) do
    @model = to_model( File.basename( file ) )
  end if file
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Maven::Tools::DSL

Instance Method Details

#pom_file(pom, dir = '.') ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/maven/tools/pom.rb', line 54

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



74
75
76
77
78
79
80
# File 'lib/maven/tools/pom.rb', line 74

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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/maven/tools/pom.rb', line 82

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_sObject



65
66
67
68
69
70
71
72
# File 'lib/maven/tools/pom.rb', line 65

def to_s
  if @model
    io = StringIO.new
    v = ::Maven::Tools::Visitor.new( io )
    v.accept_project( @model )
    io.string
  end
end