spec/ide/eclipse_spec.rb in assaf-buildr-1.3.3 vs spec/ide/eclipse_spec.rb in assaf-buildr-1.3.4

- old
+ new

@@ -39,10 +39,17 @@ default_output = classpath_xml_elements.collect("classpathentry[@kind='output']") { |n| n.attributes['path'] } raise "expected: one path attribute for kind='output', got: #{default_output.inspect}" if default_output.length > 1 default_output[0] end + # <classpathentry path="PATH" sourcepath="RETURNED_VALUE" kind="var"/> + def sourcepath_for_path path + classpath_xml_elements.collect("classpathentry[@kind='var',@path='#{path}']") do |n| + n.attributes['sourcepath'] || 'no source artifact' + end + end + def project_xml_elements task('eclipse').invoke REXML::Document.new(File.open('.project')).root.elements end end @@ -50,26 +57,61 @@ describe Buildr::Eclipse do include EclipseHelper describe "eclipse's .project file" do + + JAVA_CONTAINER = 'org.eclipse.jdt.launching.JRE_CONTAINER' + SCALA_CONTAINER = 'ch.epfl.lamp.sdt.launching.SCALA_CONTAINER' + + SCALA_NATURE = 'ch.epfl.lamp.sdt.core.scalanature' + JAVA_NATURE = 'org.eclipse.jdt.core.javanature' - describe 'scala project' do + SCALA_BUILDER = 'ch.epfl.lamp.sdt.core.scalabuilder' + JAVA_BUILDER = 'org.eclipse.jdt.core.javabuilder' + + def project_natures + project_xml_elements.collect("natures/nature") { |n| n.text } + end + + def build_commands + project_xml_elements.collect("buildSpec/buildCommand/name") { |n| n.text } + end + + describe 'java project' do + before do + write 'buildfile' + write 'src/main/java/Main.java' + end - SCALA_NATURE = 'ch.epfl.lamp.sdt.core.scalanature' - JAVA_NATURE = 'org.eclipse.jdt.core.javanature' + it 'should have Java nature' do + define('foo') + project_natures.should include(JAVA_NATURE) + end - SCALA_BUILDER = 'ch.epfl.lamp.sdt.core.scalabuilder' - JAVA_BUILDER = 'org.eclipse.jdt.core.javabuilder' - - def project_natures - project_xml_elements.collect("natures/nature") { |n| n.text } + it 'should have Java build command' do + define('foo') + build_commands.should include(JAVA_BUILDER) end + end + + describe 'nested java project' do - def build_commands - project_xml_elements.collect("buildSpec/buildCommand/name") { |n| n.text } + it 'should have name corresponding to its project definition' do + mkdir 'foo' + define('myproject') { + project.version = '1.0' + define('foo') { compile.using(:javac); package :jar } + } + task('eclipse').invoke + REXML::Document.new(File.open(File.join('foo', '.project'))).root. + elements.collect("name") { |e| e.text }.should == ['myproject-foo'] end + + end + + describe 'scala project' do before do write 'buildfile' write 'src/main/scala/Main.scala' end @@ -90,24 +132,21 @@ end describe "eclipse's .classpath file" do describe 'scala project' do - - SCALA_CONTAINER = 'ch.epfl.lamp.sdt.launching.SCALA_CONTAINER' - JAVA_CONTAINER = 'org.eclipse.jdt.launching.JRE_CONTAINER' - + def classpath_containers attribute='path' classpath_xml_elements.collect("classpathentry[@kind='con']") { |n| n.attributes[attribute] } end before do write 'buildfile' write 'src/main/scala/Main.scala' end - it 'should have SCALA_CONTAINER before JRE_CONTAINER' do + it 'should have SCALA_CONTAINER before JAVA_CONTAINER' do define('foo') classpath_containers.should include(SCALA_CONTAINER) classpath_containers.should include(JAVA_CONTAINER) classpath_containers.index(SCALA_CONTAINER).should < classpath_containers.index(JAVA_CONTAINER) end @@ -172,10 +211,16 @@ it 'should go to the default target directory' do define('foo') classpath_specific_output('src/test/java').should == 'target/test/classes' end + + it 'should accept to be the only code in the project' do + rm 'src/main/java/Main.java' + define('foo') + classpath_sources.should include('src/test/java') + end end describe 'main resources' do it_should_behave_like 'source' @@ -221,23 +266,46 @@ it 'should go to the default target directory' do define('foo') classpath_specific_output('src/test/resources').should == 'target/test/resources' end end + end - describe 'project depending on another project' do - - it 'should have the underlying project in its classpath' do - mkdir 'bar' - define('myproject') { - project.version = '1.0' - define('foo') { package :jar } - define('bar') { compile.using(:javac).with project('foo'); } - } - task('eclipse').invoke - REXML::Document.new(File.open(File.join('bar', '.classpath'))).root. - elements.collect("classpathentry[@kind='src']") { |n| n.attributes['path'] }.should include('/myproject-foo') - end + describe 'project depending on another project' do + it 'should have the underlying project in its classpath' do + mkdir 'foo' + mkdir 'bar' + define('myproject') { + project.version = '1.0' + define('foo') { package :jar } + define('bar') { compile.using(:javac).with project('foo'); } + } + task('eclipse').invoke + REXML::Document.new(File.open(File.join('bar', '.classpath'))).root. + elements.collect("classpathentry[@kind='src']") { |n| n.attributes['path'] }.should include('/myproject-foo') end end end + + describe 'maven2 artifact dependency' do + before do + define('foo') { compile.using(:javac).with('com.example:library:jar:2.0') } + artifact('com.example:library:jar:2.0') { |task| write task.name } + task('eclipse').invoke + end + + it 'should have a reference in the .classpath file relative to the local M2 repo' do + classpath_xml_elements.collect("classpathentry[@kind='var']") { |n| n.attributes['path'] }. + should include('M2_REPO/com/example/library/2.0/library-2.0.jar') + end + + it 'should be downloaded' do + file(artifact('com.example:library:jar:2.0').name).should exist + end + + it 'should have a source artifact reference in the .classpath file' do + sourcepath_for_path('M2_REPO/com/example/library/2.0/library-2.0.jar'). + should == ['M2_REPO/com/example/library/2.0/library-2.0-sources.jar'] + end + end + end