Method: Maven::Tools::GemProject#load_gemspec

Defined in:
lib/maven/tools/gem_project.rb

#load_gemspec(specfile) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/maven/tools/gem_project.rb', line 45

def load_gemspec(specfile)
  require 'rubygems'
  if specfile.is_a? ::Gem::Specification
    spec = specfile
  else
    spec = ::Gem::Specification.load(specfile)
    @gemspec = specfile
  end
  raise "file not found '#{specfile}'" unless spec
  @current_file = specfile
  artifact_id spec.name
  version spec.version
  name spec.summary || "#{self.artifact_id} - gem"
  description spec.description if spec.description
  url spec.homepage if spec.homepage
  done_authors = []
  (spec.email || []).zip(spec.authors || []).map do |email, author|
    done_authors << author
    self.developers.new(author, email)
  end
  (spec.authors - done_authors).each do |author|
    self.developers.new(author, nil)
  end

  # flatten the array since copyright-header-1.0.3.gemspec has a double
  # nested array
  (spec.licenses + spec.files.select {|file| file.to_s =~ /license|gpl/i }).flatten.each do |license|
    # TODO make this better, i.e. detect the right license name from the file itself
    self.licenses.new(license)
  end

  config = {}
   if @gemspec
     relative = File.expand_path(@gemspec).sub(/#{File.expand_path('.')}/, '').sub(/^\//, '')
     add_param(config, "gemspec", relative)
   end
  add_param(config, "autorequire", spec.autorequire)
  add_param(config, "defaultExecutable", spec.default_executable)
  add_param(config, "testFiles", spec.test_files)
  #has_rdoc always gives true => makes not sense to keep it then
  #add_param(config, "hasRdoc", spec.has_rdoc)
  add_param(config, "extraRdocFiles", spec.extra_rdoc_files)
  add_param(config, "rdocOptions", spec.rdoc_options)
  add_param(config, "requirePaths", spec.require_paths, ["lib"])
  add_param(config, "rubyforgeProject", spec.rubyforge_project)
  add_param(config, "requiredRubygemsVersion",
            spec.required_rubygems_version && spec.required_rubygems_version.to_s != ">= 0" ? "<![CDATA[#{spec.required_rubygems_version}]]>" : nil)
  add_param(config, "bindir", spec.bindir, "bin")
  add_param(config, "requiredRubyVersion",
            spec.required_ruby_version && spec.required_ruby_version.to_s != ">= 0" ? "<![CDATA[#{spec.required_ruby_version}]]>" : nil)
  add_param(config, "postInstallMessage",
            spec.post_install_message ? "<![CDATA[#{spec.post_install_message}]]>" : nil)
  add_param(config, "executables", spec.executables)
  add_param(config, "extensions", spec.extensions)
  add_param(config, "platform", spec.platform, 'ruby')

  # # TODO maybe calculate extra files
  # files = spec.files.dup
  # (Dir['lib/**/*'] + Dir['spec/**/*'] + Dir['features/**/*'] + Dir['test/**/*'] + spec.licenses + spec.extra_rdoc_files).each do |f|
  #   files.delete(f)
  #   if f =~ /^.\//
  #     files.delete(f.sub(/^.\//, ''))
  #   else
  #     files.delete("./#{f}")
  #   end
  # end
  #add_param(config, "extraFiles", files)
  add_param(config, "files", spec.files)

  plugin('gem').with(config) if config.size > 0

  spec.dependencies.each do |dep|
    scope =
      case dep.type
      when :runtime
        "compile"
      when :development
        "test"
      else
        warn "unknown scope: #{dep.type}"
        "compile"
      end

    versions = dep.requirement.requirements.collect do |req|
      # use this construct to get the same result in 1.8.x and 1.9.x
      req.collect{ |i| i.to_s }.join
    end
    add_gem(dep.name, versions).scope = scope
    if @lock
      # add its dependencies as well to have the version
      # determine by the dependencyManagement
      @lock.dependency_hull(dep.name).map.each do |d|
        add_gem(d[0], d[1]).scope = scope unless gem? d[0]
      end
    end
  end

  spec.requirements.each do |req|
    begin
      eval req
    rescue => e
      # TODO requirements is a list !!!
      add_param(config, "requirements", req)
    rescue SyntaxError => e
      # TODO requirements is a list !!!
      add_param(config, "requirements", req)
    rescue NameError => e
      # TODO requirements is a list !!!
      add_param(config, "requirements", req)
    end
  end
end