buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From boisv...@apache.org
Subject svn commit: r901534 - in /buildr/trunk: CHANGELOG lib/buildr/ide/eclipse.rb spec/ide/eclipse_spec.rb
Date Thu, 21 Jan 2010 05:30:17 GMT
Author: boisvert
Date: Thu Jan 21 05:30:08 2010
New Revision: 901534

URL: http://svn.apache.org/viewvc?rev=901534&view=rev
Log:
BUILDR-361 Generate Eclipse .project file even if project has no nature.
Also prevent generation of .project if project has children. (Antoine Toulme)


Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/lib/buildr/ide/eclipse.rb
    buildr/trunk/spec/ide/eclipse_spec.rb

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=901534&r1=901533&r2=901534&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Thu Jan 21 05:30:08 2010
@@ -36,6 +36,9 @@
           even if mapping is provided
 * Fixed:  BUILDR-360 Reintroduce tag_name instance method for Git release task for
           backward compatibility (Antoine Toulme)
+* Fixed:  BUILDR-361 Generate Eclipse .project file even if project has no
+          nature.  Also prevent generation of .project if project has
+          children. (Antoine Toulme)
 * Fixed:  Fail-fast if package.with() or include() called with nil values
 * Fixed:  Failures not reported correctly for ScalaTest (Alex Eagle)
 * Fixed:  Test dependencies should include test compile dependencies

Modified: buildr/trunk/lib/buildr/ide/eclipse.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/ide/eclipse.rb?rev=901534&r1=901533&r2=901534&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/ide/eclipse.rb (original)
+++ buildr/trunk/lib/buildr/ide/eclipse.rb Thu Jan 21 05:30:08 2010
@@ -192,88 +192,93 @@
 
     after_define(:eclipse => :package) do |project|
       eclipse = project.task('eclipse')
+      # We don't create the .project and .classpath files if the project contains projects.
+      if project.projects.empty?
 
-      eclipse.enhance [ file(project.path_to('.classpath')), file(project.path_to('.project'))
]
+        eclipse.enhance [ file(project.path_to('.classpath')), file(project.path_to('.project'))
]
 
-      # The only thing we need to look for is a change in the Buildfile.
-      file(project.path_to('.classpath')=>Buildr.application.buildfile) do |task|
-        if (project.eclipse.natures.reject { |x| x.is_a?(Symbol) }.size > 0)
-          info "Writing #{task.name}"
+        # The only thing we need to look for is a change in the Buildfile.
+        file(project.path_to('.classpath')=>Buildr.application.buildfile) do |task|
+          if (project.eclipse.natures.reject { |x| x.is_a?(Symbol) }.size > 0)
+            info "Writing #{task.name}"
+
+            m2repo = Buildr::Repositories.instance.local
+
+            File.open(task.name, 'w') do |file|
+              classpathentry = ClasspathEntryWriter.new project, file
+              classpathentry.write do
+                # Note: Use the test classpath since Eclipse compiles both "main" and "test"
classes using the same classpath
+                cp = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s,
project.resources.target.to_s ]
+                cp = cp.uniq
+
+                # Convert classpath elements into applicable Project objects
+                cp.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect {
|pkg| pkg.to_s == path } } || path }
+
+                # Remove excluded libs
+                cp -= project.eclipse.exclude_libs.map(&:to_s)
+
+                # project_libs: artifacts created by other projects
+                project_libs, others = cp.partition { |path| path.is_a?(Project) }
+
+                # Separate artifacts under known classpath variable paths
+                # including artifacts located in local Maven2 repository
+                vars = []
+                project.eclipse.classpath_variables.merge(project.eclipse.options.m2_repo_var
=> m2repo).each do |name, path|
+                  matching, others = others.partition { |f| File.expand_path(f.to_s).index(path)
== 0 }
+                  matching.each do |m|
+                    vars << [m, name, path]
+                  end
+                end
 
-          m2repo = Buildr::Repositories.instance.local
+                # Generated: Any non-file classpath elements in the project are assumed to
be generated
+                libs, generated = others.partition { |path| File.file?(path.to_s) }
 
-          File.open(task.name, 'w') do |file|
-            classpathentry = ClasspathEntryWriter.new project, file
-            classpathentry.write do
-              # Note: Use the test classpath since Eclipse compiles both "main" and "test"
classes using the same classpath
-              cp = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s,
project.resources.target.to_s ]
-              cp = cp.uniq
-
-              # Convert classpath elements into applicable Project objects
-              cp.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect { |pkg|
pkg.to_s == path } } || path }
-
-              # Remove excluded libs
-              cp -= project.eclipse.exclude_libs.map(&:to_s)
-
-              # project_libs: artifacts created by other projects
-              project_libs, others = cp.partition { |path| path.is_a?(Project) }
-
-              # Separate artifacts under known classpath variable paths
-              # including artifacts located in local Maven2 repository
-              vars = []
-              project.eclipse.classpath_variables.merge(project.eclipse.options.m2_repo_var
=> m2repo).each do |name, path|
-                matching, others = others.partition { |f| File.expand_path(f.to_s).index(path)
== 0 }
-                matching.each do |m|
-                  vars << [m, name, path]
+                classpathentry.src project.compile.sources + generated
+                classpathentry.src project.resources
+
+                if project.test.compile.target
+                  classpathentry.src project.test.compile
+                  classpathentry.src project.test.resources
                 end
-              end
 
-              # Generated: Any non-file classpath elements in the project are assumed to
be generated
-              libs, generated = others.partition { |path| File.file?(path.to_s) }
+                # Classpath elements from other projects
+                classpathentry.src_projects project_libs
 
-              classpathentry.src project.compile.sources + generated
-              classpathentry.src project.resources
+                classpathentry.output project.compile.target if project.compile.target
+                classpathentry.lib libs
+                classpathentry.var vars
 
-              if project.test.compile.target
-                classpathentry.src project.test.compile
-                classpathentry.src project.test.resources
+                project.eclipse.classpath_containers.each { |container|
+                  classpathentry.con container
+                }
               end
-
-              # Classpath elements from other projects
-              classpathentry.src_projects project_libs
-
-              classpathentry.output project.compile.target if project.compile.target
-              classpathentry.lib libs
-              classpathentry.var vars
-
-              project.eclipse.classpath_containers.each { |container|
-                classpathentry.con container
-              }
             end
           end
         end
-      end
 
-      # The only thing we need to look for is a change in the Buildfile.
-      file(project.path_to('.project')=>Buildr.application.buildfile) do |task|
-        if (project.eclipse.natures.reject { |x| x.is_a?(Symbol) }.size > 0)
+        # The only thing we need to look for is a change in the Buildfile.
+        file(project.path_to('.project')=>Buildr.application.buildfile) do |task|
           info "Writing #{task.name}"
           File.open(task.name, 'w') do |file|
             xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
             xml.projectDescription do
               xml.name project.id
               xml.projects
-              xml.buildSpec do
-                project.eclipse.builders.each { |builder|
-                  xml.buildCommand do
-                    xml.name builder
-                  end
-                }
+              unless project.eclipse.builders.empty?
+                xml.buildSpec do
+                  project.eclipse.builders.each { |builder|
+                    xml.buildCommand do
+                      xml.name builder
+                    end
+                  }
+                end
               end
-              xml.natures do
-                project.eclipse.natures.each { |nature|
-                  xml.nature nature unless nature.is_a? Symbol
-                }
+              unless project.eclipse.natures.empty?
+                xml.natures do
+                  project.eclipse.natures.each { |nature|
+                    xml.nature nature unless nature.is_a? Symbol
+                  }
+                end
               end
             end
           end

Modified: buildr/trunk/spec/ide/eclipse_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/ide/eclipse_spec.rb?rev=901534&r1=901533&r2=901534&view=diff
==============================================================================
--- buildr/trunk/spec/ide/eclipse_spec.rb (original)
+++ buildr/trunk/spec/ide/eclipse_spec.rb Thu Jan 21 05:30:08 2010
@@ -85,6 +85,52 @@
 
   describe "eclipse's .project file" do
 
+    describe 'default project' do
+      before do
+        write 'buildfile'
+        write 'src/main/nono/Main.nono'
+      end
+      
+      it 'should not have natures' do
+        define('foo')
+        project_natures.should be_empty
+      end
+
+      it 'should not have build commands' do
+        define('foo')
+        build_commands.should be_empty
+      end
+      
+      it 'should generate a .project file' do
+        define('foo')
+        task('eclipse').invoke
+        REXML::Document.new(File.open('.project')).root.
+          elements.collect("name") { |e| e.text }.should == ['foo']
+      end
+      
+      it 'should not generate a .classpath file' do
+        define('foo')
+        task('eclipse').invoke
+        File.exists?('.classpath').should be_false
+      end
+    end
+    
+    describe 'parent project' do
+      before do
+        write 'buildfile'
+        mkpath 'bar'
+      end
+
+      it 'should not generate a .project for the parent project' do
+        define('foo') do
+          define('bar')
+        end
+        task('eclipse').invoke
+        File.exists?('.project').should be_false
+        File.exists?(File.join('bar','.project')).should be_true
+      end
+    end
+    
     describe 'java project' do
       before do
         write 'buildfile'



Mime
View raw message