Class: Maven::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/maven.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, settings) ⇒ Project

Returns a new instance of Project.



168
169
170
171
172
173
174
175
176
177
# File 'lib/maven.rb', line 168

def initialize(name, settings)
  self.name = name
  self.verbose = false
  settings.each do |key, value|
    send("#{key}=", value)
  end
  @pom_dir||= name.dup
  @rake_prefix ||= "java"
  @plugin_settings ||= DEFAULT_MVN_PLUGINS_SETTING
end

Instance Attribute Details

#artifact_idObject

Returns the value of attribute artifact_id.



160
161
162
# File 'lib/maven.rb', line 160

def artifact_id
  @artifact_id
end

#group_idObject

Returns the value of attribute group_id.



159
160
161
# File 'lib/maven.rb', line 159

def group_id
  @group_id
end

#nameObject

Returns the value of attribute name.



162
163
164
# File 'lib/maven.rb', line 162

def name
  @name
end

#plugin_settingsObject

Returns the value of attribute plugin_settings.



165
166
167
# File 'lib/maven.rb', line 165

def plugin_settings
  @plugin_settings
end

#pom_dirObject

Returns the value of attribute pom_dir.



163
164
165
# File 'lib/maven.rb', line 163

def pom_dir
  @pom_dir
end

#rake_prefixObject

Returns the value of attribute rake_prefix.



164
165
166
# File 'lib/maven.rb', line 164

def rake_prefix
  @rake_prefix
end

#verboseObject

Returns the value of attribute verbose.



166
167
168
# File 'lib/maven.rb', line 166

def verbose
  @verbose
end

Instance Method Details

#archetype_create_argsObject



183
184
185
186
187
# File 'lib/maven.rb', line 183

def archetype_create_args
  %w(group_id artifact_id).map do |key|
    "#{key}=#{send(key)}"
  end
end

#execute(goal, mvn_args = nil, &block) ⇒ Object



221
222
223
# File 'lib/maven.rb', line 221

def execute(goal, mvn_args = nil, &block)
  execute_with_cd(goal, mvn_args, &block)
end

#execute_with_cd(goal, mvn_args = nil, &block) ⇒ Object



212
213
214
215
216
217
218
219
# File 'lib/maven.rb', line 212

def execute_with_cd(goal, mvn_args = nil, &block)
  FileUtils.cd(pom_dir, :verbose => verbose) do
    unless File.exist?("pom.xml")
      raise "You must execute 'rake mvn:create' before #{ARGV.join(' ')}"
    end
    execute_without_cd(goal, mvn_args, &block)
  end
end

#execute_without_cd(goal, mvn_args = nil, &block) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/maven.rb', line 198

def execute_without_cd(goal, mvn_args = nil, &block)
  unless mvn_args
    mvn_args = ARGV.dup
    mvn_args.shift
  end
  command = "mvn #{goal} " + mvn_args.map do |arg|
    key, value = *arg.split('=', 2)
    "-D#{key.java_style}=#{value}"
  end.join(" ")
  block ||= lambda{|f| puts f.read }
  puts(command) if verbose
  open("|#{command}", "r", &block)
end

#plugin(plugin_name) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/maven.rb', line 225

def plugin(plugin_name)
  lines = nil
  execute("help:describe", ["plugin=#{plugin_name}", "full=true"]) do |f|
    lines = f.readlines
  end
  lines.each{|line| line.chomp!}
  if lines.any?{|line| /^\ERROR\]/ =~ line}
    raise lines.join
    return nil
  end
  plugin = Plugin.new(plugin_name)
  lines.inject(plugin) do |current, line|
    current.process(line)
  end
  plugin.prepare
  plugin
end

#plugin_setting_pathObject



179
180
181
# File 'lib/maven.rb', line 179

def plugin_setting_path
  File.join(pom_dir, plugin_settings)
end

#select_plugins(*args) ⇒ Object



189
190
191
192
193
194
195
196
# File 'lib/maven.rb', line 189

def select_plugins(*args)
  plugins = YAML.load_file(plugin_setting_path).sort
  args.each do |arg|
    regexp = Regexp.new(arg)
    plugins = plugins.select{|plugin| plugin =~ regexp}
  end
  plugins
end