require 'maven/model/model' describe Maven::Model do describe Maven::Model::Project do before :each do @project = Maven::Model::Project.new("test:project", '0.0.0') end it 'should setup a project with split args' do Maven::Model::Project.new("test", "project", "1.0.0").to_xml.should == <<-XML 4.0.0 test project 1.0.0 XML end it 'should setup a minimal project' do project = Maven::Model::Project.new project.dump_pom 'pom-ng.xml' project.artifact_id = 'mini' project.parent('test:parent', '1.2.3') project.to_xml.should == <<-XML 4.0.0 test parent 1.2.3 mini XML end it 'should setup a project with parent' do @project.parent("test:parent", '0.1.2').relative_path='../pom.rb' @project.to_xml.should == <<-XML 4.0.0 test parent 0.1.2 ../pom.rb test project 0.0.0 XML end it 'should setup a project with metadata' do @project.name "name" @project.packaging = :jar @project.description <<-TXT some text more TXT @project.url "http://example.com" @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 jar http://example.com XML end it 'should setup a project with developers' do @project.developers.new("my name1", "my_email1@example.com") @project.developers.new("my name2 ") @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 my_email1_at_example_dot_com my name1 my_email1@example.com my_email2_at_example_dot_com my name2 my_email2@example.com XML end it 'should setup a project with licenses' do @project.licenses.new("MIT-LICENSE.txt") @project.licenses.new("http://www.gnu.org/licenses/gpl.html") @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 MIT-LICENSE ./MIT-LICENSE.txt repo gpl http://www.gnu.org/licenses/gpl.html repo XML end it 'should setup a project with repositories' do @project.repository("rubygems-releases", "http://rubygems-proxy.torquebox.org/releases") @project.plugin_repository("sonatype-snapshots") do |sonatype| sonatype.url "http://oss.sonatype.org/content/repositories/snapshots" sonatype.releases(:enabled => false) sonatype.snapshots(:enabled => true) end @project.repository("jboss-public-repository-group") do |jboss| jboss.name "JBoss Public Maven Repository Group" jboss.url "https://repository.jboss.org/nexus/content/groups/public-jboss/" jboss.releases(:enabled => false, :updatePolicy => :never, :checksumPolicy => :strict) jboss.snapshots(:enabled => true, :updatePolicy => :daily, :checksumPolicy => :ignore) end @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 rubygems-releases http://rubygems-proxy.torquebox.org/releases jboss-public-repository-group JBoss Public Maven Repository Group https://repository.jboss.org/nexus/content/groups/public-jboss/ false never strict true daily ignore sonatype-snapshots http://oss.sonatype.org/content/repositories/snapshots false true XML end it 'should setup a project with properties' do @project.properties["gem.home"] = "${project.build.directory}/rubygems" @project.properties = { "gem.home" => "${user.home}/.gem/jruby/1.8" } @project.properties["gem.path"] = "${project.build.directory}/rubygems" @project.properties["jruby.plugins.version"] = "0.26.0-SNAPSHOT" @project.properties["project.build.sourceEncoding"] = "UTF-8" @project.properties.merge!({ "gem.path" => "${user.home}/.gem/jruby/1.8" }) @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 ${user.home}/.gem/jruby/1.8 ${user.home}/.gem/jruby/1.8 0.26.0-SNAPSHOT UTF-8 XML end it 'should setup a project with source control management' do @project.source_control do |sc| sc.connection 'scm:git:git://github.com/torquebox/maven-tools.git' sc.developer_connection 'scm:git:ssh://git@github.com/torquebox/maven-tools.git' sc.url 'http://github.com/torquebox/maven-tools' end @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 scm:git:git://github.com/torquebox/maven-tools.git scm:git:ssh://git@github.com/torquebox/maven-tools.git http://github.com/torquebox/maven-tools XML end it 'should setup a project with dependencies and dependency_management' do @project.dependency_management do |deps| deps.gem "slf4r", "0.4.2" deps.jar "org.slf4j:slf4j-simple", "1.6.2" end @project.dependency_management.gem "rspec", "2.4.1" @project.dependencies do |d| d.gem "rspec" d.test_jar "org.slf4j:slf4j-noop", "1.6.2" end @project.gem "rspec" @project.test_jar "org.slf4j:slf4j-noop", "1.6.2" @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 rubygems rspec [0,) gem org.slf4j slf4j-noop 1.6.2 jar test rubygems slf4r 0.4.2 gem org.slf4j slf4j-simple 1.6.2 jar rubygems rspec 2.4.1 gem XML end it 'should setup a project with dependency with exclusions' do @project.jar 'org.xerial:sqlite-jdbc', '3.6.10' do |j| j.exclude 'org.xerial.thirdparty:nestedvm' end @project.gem 'sqlite-jdbc', '3.6.10' @project.gem('sqlite-jdbc').exclude 'nestedvm' @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 org.xerial sqlite-jdbc 3.6.10 jar org.xerial.thirdparty nestedvm rubygems sqlite-jdbc 3.6.10 gem rubygems nestedvm XML end it 'should allow to set maven core plugins directly in the project' do @project.plugin 'release' @project.plugin("clean", "2.4.1") @project.plugin(:compile, "2.3.2").with :source => "1.5", :target => "1.5" @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 maven-release-plugin maven-clean-plugin 2.4.1 maven-compile-plugin 2.3.2 1.5 1.5 XML end it 'should allow to set jruby plugins directly in the project' do @project.plugin(:gem).extensions true @project.plugin(:gem).in_phase("pre-integration-test").execute_goal(:install) @project.plugin(:cucumber).in_phase("integration-test").execute_goal(:test).with(:cucumberArgs => "--no-colors") @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 de.saumya.mojo gem-maven-plugin true in_phase_pre_integration_test pre-integration-test install de.saumya.mojo cucumber-maven-plugin in_phase_integration_test integration-test test --no-colors XML end it 'should allow to configure plugins in various ways' do @project.plugin('org.codehaus.mojo:gwt-maven-plugin', '2.1.0') do |gwt| gwt.with({ :extraJvmArgs => "-Xmx512m", :runTarget => "example.html" }) gwt.execution.goals << ["clean", "compile", "test"] end @project.plugin("org.mortbay.jetty:jetty-maven-plugin", "7.2.2.v20101205").with({ :connectors => <<-XML 8080 8443 ${project.basedir}/src/test/resources/server.keystore 123456 123456 XML }) @project.plugin(:war).with({ :webResources => Maven::Model::NamedArray.new(:resource) do |l| l << { :directory => "public" } l << { :directory => ".", :targetPath => "WEB-INF", :includes => ['app/**', 'config/**', 'lib/**', 'vendor/**', 'Gemfile'] } l << { :directory => '${gem.path}', :targetPath => 'WEB-INF/gems' } end }) @project.to_xml.should == <<-XML 4.0.0 test project 0.0.0 org.codehaus.mojo gwt-maven-plugin 2.1.0 -Xmx512m example.html clean compile test org.mortbay.jetty jetty-maven-plugin 7.2.2.v20101205 8080 8443 ${project.basedir}/src/test/resources/server.keystore 123456 123456 maven-war-plugin public . WEB-INF app/** config/** lib/** vendor/** Gemfile ${gem.path} WEB-INF/gems XML end end describe Maven::Model::Build do before :each do @build = Maven::Model::Build.new end it 'should setup an empty build' do @build.to_xml.should == "" end it 'should setup a build with final_name' do @build.final_name "final" @build.to_xml.should == <<-XML final XML end it 'should setup a build with resources' do @build.resources.add do |r| r.target_path "${project.basedir}" r.filtering false r.directory "${project.build.directory}/apache-maven-${maven.version}" r.includes += ["**/*.rb", "*.java"] r.excludes << 'test.rb' end @build.to_xml.should == <<-XML ${project.build.directory}/apache-maven-${maven.version} **/*.rb *.java test.rb ${project.basedir} XML end it 'should setup a build with test-resources' do @build.test_resources do |res| res.add do |r| r.target_path "${project.basedir}" r.directory "${project.build.directory}/apache-maven-${maven.version}" r.filtering false end res.add do |r| r.target_path "${project.basedir}" r.directory "${project.build.directory}" r.filtering true end end @build.to_xml.should == <<-XML ${project.build.directory}/apache-maven-${maven.version} ${project.basedir} ${project.build.directory} ${project.basedir} true XML end end describe Maven::Model::Profile do before :each do @profile = Maven::Model::Profile.new(:test) end it 'should setup an empty profile' do @profile.to_xml.should == <<-XML test XML end it 'should setup a profile with activation by default' do @profile.activation.by_default @profile.to_xml.should == <<-XML test true XML end it 'should setup a profile with activation by property' do @profile.activation.property("rails.env", "test") @profile.to_xml.should == <<-XML test rails.env test XML end it 'should setup a profile with activation by OS family' do @profile.activation.os.family "mac" @profile.to_xml.should == <<-XML test mac XML end it 'should setup a profile with properties' do @profile.properties.merge!({ "gem.home" => "${project.build.directory}/rubygems-production", "gem.path" => "${project.build.directory}/rubygems-production" }) @profile.to_xml.should == <<-XML test ${project.build.directory}/rubygems-production ${project.build.directory}/rubygems-production XML end it 'should setup a profile with plugins' do @profile.plugin("org.mortbay.jetty:jetty-maven-plugin", "${jetty.version}") @profile.to_xml.should == <<-XML test org.mortbay.jetty jetty-maven-plugin ${jetty.version} XML end it 'should setup a profile with gem dependency and dependency_management' do @profile.gem "cucumber", nil @profile.dependency_management.gem "cucumber", "0.9.4" @profile.to_xml.should == <<-XML test rubygems cucumber gem rubygems cucumber 0.9.4 gem XML end end end