Module: Maven

Defined in:
lib/maven.rb

Defined Under Namespace

Modules: IgnoreNilElement Classes: Base, Goal, Parameter, Plugin, Project, Skipper

Constant Summary collapse

DEFAULT_PROJECT_SETTINGS =
"mvn_projects.yml"
PLUGINS =
%w(clean compiler deploy install resources site surefire verifier) + 
# packaging types / tools
%w(ear ejb jar rar war shade) + 
# reporting
%w(changelog changes checkstyle clover doap docck javadoc jxr pmd project-info-reports surefire-report) +
# tools
%w(ant antrun archetype assembly dependency enforcer gpg help invoker one patch plugin release remote-resources repository scm source stage) +
# IDEs
%w(eclipse idea) +
# Outside The Maven Land
%w(build-helper castor javacc jdepend native sql taglist) +
# A number of other projects provide their own Maven plugins. This includes
%w(cargo jaxme jetty jalopy)
LIFECYCLES =
[
 # Clean Lifecycle
 { :name => "pre-clean", :desc => "executes processes needed prior to the actual project cleaning"},
 { :name => "clean", :desc => "remove all files generated by the previous build"},
 { :name => "post-clean", :desc => "executes processes needed to finalize the project cleaning"},
 # Default Lifecycle
 { :name => "validate", :desc => "validate the project is correct and all necessary information is available."},
 { :name => "generate-sources", :desc => "generate any source code for inclusion in compilation."},
 { :name => "process-sources", :hidden => true, :desc => "process the source code, for example to filter any values."},
 { :name => "generate-resources", :desc => "generate resources for inclusion in the package."},
 { :name => "process-resources", :hidden => true, :desc => "copy and process the resources into the destination directory, ready for packaging."},
 { :name => "compile", :desc => "compile the source code of the project."},
 { :name => "process-classes", :hidden => true, :desc => "post-process the generated files from compilation, for example to do bytecode enhancement on Java classes."},
 { :name => "generate-test-sources", :desc => "generate any test source code for inclusion in compilation."},
 { :name => "process-test-sources", :hidden => true, :desc => "process the test source code, for example to filter any values."},
 { :name => "generate-test-resources", :desc => "create resources for testing."},
 { :name => "process-test-resources", :hidden => true, :desc => "copy and process the resources into the test destination directory."},
 { :name => "test-compile", :desc => "compile the test source code into the test destination directory"},
 { :name => "process-test-classes", :hidden => true, :desc => "post-process the generated files from test compilation, for example to do bytecode enhancement on Java classes. For Maven 2.0.5 and above."},
 { :name => "test", :desc => "run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed."},
 { :name => "prepare-package", :hidden => true, :desc => "perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above)"},
 { :name => "package", :desc => "take the compiled code and package it in its distributable format, such as a JAR."},
 { :name => "pre-integration-test", :hidden => true, :desc => "perform actions required before integration tests are executed. This may involve things such as setting up the required environment."},
 { :name => "integration-test", :desc => "process and deploy the package if necessary into an environment where integration tests can be run."},
 { :name => "post-integration-test", :hidden => true, :desc => "perform actions required after integration tests have been executed. This may including cleaning up the environment."},
 { :name => "verify", :desc => "run any checks to verify the package is valid and meets quality criteria."},
 { :name => "install", :desc => "install the package into the local repository, for use as a dependency in other projects locally."},
 { :name => "deploy", :desc => "done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects."},
 # Site Lifecycle
 { :name => "pre-site", :hidden => true, :desc => "executes processes needed prior to the actual project site generation"},
 { :name => "site", :desc => "generates the project's site documentation"},
 { :name => "post-site", :hidden => true, :desc => "executes processes needed to finalize the site generation, and to prepare for site deployment"},
 { :name => "site-deploy", :desc => "deploys the generated site documentation to the specified web server"}
]
LIFECYCLE_BIDINGS =
{
  # Clean Lifecycle Bindings
  "clean" => "clean:clean",
  # Default Lifecycle Bindings - Packaging ejb / ejb3 / jar / par / rar / war
  "process-resources" => "resources:resources",
  "compile" => "compiler:compile",
  "process-test-resources" => "resources:testResource",
  "test-compile" => "compiler:testCompile",
  "test" => "surefire:test",
  "package" => "ejb:ejb or ejb3:ejb3 or jar:jar or par:par or rar:rar or war:war",
  "install" => "install:install",
  "deploy" => "deploy:deploy",
  # Default Lifecycle Bindings - Packaging ear
  "generate-resources" => "ear:generateApplicationXml",
  "process-resources" => "resources:resources",
  "package" => "ear:ear",
  "install" => "install:install",
  "deploy" => "deploy:deploy",
  # Default Lifecycle Bindings - Packaging maven-plugin
  "generate-resources" => "plugin:descriptor",
  "process-resources" => "resources:resources",
  "compile" => "compiler:compile",
  "process-test-resources" => "resources:testResource",
  "test-compile" => "compiler:testCompile",
  "test" => "surefire:test",
  "package" => "jar:jar and plugin:addPluginArtifactMetadata",
  "install" => "install:install and plugin:updateRegistry",
  "deploy" => "deploy:deploy",
  # Default Lifecycle Bindings - Packaging pom
  "package" => "site:attach-descriptor",
  "install" => "install:install",
  "deploy" => "deploy:deploy",
  # Site Lifecycle Bindings",
  "site" => "site:site",
  "site-deploy" => "site:deploy"
}
DEFAULT_MVN_PLUGINS_SETTING =
"mvn_plugins.yml"

Class Method Summary collapse

Class Method Details

.create_project(filename, settings = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/maven.rb', line 26

def self.create_project(filename, settings = nil)
  if filename.is_a?(Hash)
    Project.new("unnamed", filename)
  elsif /\.xml\Z/i =~ filename
    raise ArgumentError, "#{filename} not found" unless File.exist?(filename)
    open(filename) do |f|
      pom = REXML::Document.new(f)
      pom.elements.each("project") do |proj|
        proj.extend(IgnoreNilElement)
        settings = {
          'rake_prefix' => 'mvn', 
          'pom_dir' => File.dirname(filename).gsub(/[\\\/]/, '_')
        }.update(settings || {})
        settings.update({
          'group_id' => proj.text_value('groupId'),
          'artifact_id' => proj.text_value('artifactId')
          })
        return Project.new(proj.text_value('name', 'artifactId'), settings)
      end
    end
  else
    raise ArgumentError, "unsupported file: #{filename}"
  end
end

.create_projects(settings) ⇒ Object



51
52
53
54
55
# File 'lib/maven.rb', line 51

def self.create_projects(settings)
  settings.map do |name, setting|
    Project.new(name, setting)
  end
end