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.0testproject1.0.0
XML
end
it 'should setup a minimal project' do
project = Maven::Model::Project.new
project.artifact_id = 'mini'
project.parent('test:parent', '1.2.3')
project.to_xml.should == <<-XML
4.0.0testparent1.2.3mini
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.0testparent0.1.2../pom.rbtestproject0.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.0testproject0.0.0jarhttp://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.0testproject0.0.0my_email1_at_example_dot_commy name1my_email1@example.commy_email2_at_example_dot_commy name2my_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.0testproject0.0.0MIT-LICENSE./MIT-LICENSE.txtrepogplhttp://www.gnu.org/licenses/gpl.htmlrepo
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.0testproject0.0.0jboss-public-repository-groupJBoss Public Maven Repository Grouphttps://repository.jboss.org/nexus/content/groups/public-jboss/strictfalseneverignoretruedailyrubygems-releaseshttp://rubygems-proxy.torquebox.org/releasessonatype-snapshotshttp://oss.sonatype.org/content/repositories/snapshotsfalsetrue
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.0testproject0.0.0${user.home}/.gem/jruby/1.8${user.home}/.gem/jruby/1.80.26.0-SNAPSHOTUTF-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.0testproject0.0.0scm:git:git://github.com/torquebox/maven-tools.gitscm:git:ssh://git@github.com/torquebox/maven-tools.githttp://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.0testproject0.0.0rubygemsrspec[0,)gemorg.slf4jslf4j-noop1.6.2jartestrubygemsslf4r0.4.2gemorg.slf4jslf4j-simple1.6.2jarrubygemsrspec2.4.1gem
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.0testproject0.0.0org.xerialsqlite-jdbc3.6.10jarorg.xerial.thirdpartynestedvmrubygemssqlite-jdbc3.6.10gemrubygemsnestedvm
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.0testproject0.0.0maven-clean-plugin2.4.1maven-compile-plugin2.3.21.51.5maven-release-plugin
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.0testproject0.0.0de.saumya.mojocucumber-maven-pluginin_phase_integration_testintegration-testtest--no-colorsde.saumya.mojogem-maven-plugintruein_phase_pre_integration_testpre-integration-testinstall
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
80808443${project.basedir}/src/test/resources/server.keystore123456123456
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.0testproject0.0.0maven-war-pluginpublic.app/**config/**lib/**vendor/**GemfileWEB-INF${gem.path}WEB-INF/gemsorg.codehaus.mojogwt-maven-plugin2.1.0-Xmx512mexample.htmlcleancompiletestorg.mortbay.jettyjetty-maven-plugin7.2.2.v2010120580808443${project.basedir}/src/test/resources/server.keystore123456123456
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*.javatest.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
testtrue
XML
end
it 'should setup a profile with activation by property' do
@profile.activation.property("rails.env", "test")
@profile.to_xml.should == <<-XML
testrails.envtest
XML
end
it 'should setup a profile with activation by OS family' do
@profile.activation.os.family "mac"
@profile.to_xml.should == <<-XML
testmac
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
testorg.mortbay.jettyjetty-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
testrubygemscucumbergemrubygemscucumber0.9.4gem
XML
end
end
end