You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by bo...@apache.org on 2009/11/17 00:35:47 UTC

svn commit: r881053 - in /buildr/trunk: CHANGELOG lib/buildr/ide/eclipse.rb lib/buildr/ide/eclipse/scala.rb spec/ide/eclipse_spec.rb

Author: boisvert
Date: Mon Nov 16 23:35:47 2009
New Revision: 881053

URL: http://svn.apache.org/viewvc?rev=881053&view=rev
Log:
Support for excluding libraries from Eclipse classpath

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

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=881053&r1=881052&r2=881053&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Mon Nov 16 23:35:47 2009
@@ -6,6 +6,8 @@
 * Added:  Support for Eclipse classpath variables to avoid absolute pathnames in
           generated .classpath using: 
             eclipse.classpath_variables { :VAR => '/path/to/libraries' }
+* Added:  Support for excluding libraries from Eclipse classpath using:
+            eclipse.exclude_libs += ['/path/to/some/library.jar']
 * Change: Updated to JRuby 1.4.0
 * Fixed:  BUILDR-223 Release Task: customizable commit message (Alexis Midon)
 * Fixed:  BUILDR-330  Install task should re-install artifact even if they 

Modified: buildr/trunk/lib/buildr/ide/eclipse.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/ide/eclipse.rb?rev=881053&r1=881052&r2=881053&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/ide/eclipse.rb (original)
+++ buildr/trunk/lib/buildr/ide/eclipse.rb Mon Nov 16 23:35:47 2009
@@ -44,7 +44,14 @@
           values = values[0].inject({}) { |h, (k,v)| h[k.to_s] = @project.path_to(v); h }
           @variables = values.merge(@variables || {})
         end
-        @variables || (@project.parent ? @project.parent.eclipse.classpath_variables : {})
+        @variables || (@project.parent ? @project.parent.eclipse.classpath_variables : default_classpath_variables)
+      end
+
+      def default_classpath_variables
+        vars = {}
+        vars[:SCALA_HOME] = ENV['SCALA_HOME'] if ENV['SCALA_HOME']
+        vars[:JAVA_HOME]  = ENV['JAVA_HOME']  if ENV['JAVA_HOME']
+        vars
       end
 
       # :call-seq:
@@ -97,6 +104,26 @@
       end
 
       # :call-seq:
+      #   exclude_libs() => [lib1, lib2]
+      # Returns the an array of libraries to be excluded from the generated Eclipse classpath
+      def exclude_libs(*values)
+        if values.size > 0
+          @exclude_libs ||= []
+          @exclude_libs += values
+        else
+          @exclude_libs || (@project.parent ? @project.parent.eclipse.exclude_libs : [])
+        end
+      end
+
+      # :call-seq:
+      #   exclude_libs=(lib1, lib2)
+      # Sets libraries to be excluded from the generated Eclipse classpath
+      #
+      def exclude_libs=(libs)
+        @exclude_libs = arrayfy(libs)
+      end
+
+      # :call-seq:
       #   builders=(builders)
       # Sets the Eclipse project builders on the project.
       #
@@ -185,6 +212,9 @@
               # 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) }
 
@@ -308,14 +338,14 @@
       def var(libs)
         libs.each do |lib_path, var_name, var_value|
           lib_artifact = file(lib_path)
-          relative_lib_path = lib_path.sub(var_value, var_name)
+          relative_lib_path = lib_path.sub(var_value, var_name.to_s)
           if lib_artifact.respond_to? :sources_artifact
             source_path = lib_artifact.sources_artifact.to_s
             relative_source_path = source_path.sub(var_value, var_name)
             @xml.classpathentry :kind=>'var', :path=>relative_lib_path, :sourcepath=>relative_source_path
           else
             @xml.classpathentry :kind=>'var', :path=>relative_lib_path
-          end            
+          end
         end
       end
 

Modified: buildr/trunk/lib/buildr/ide/eclipse/scala.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/ide/eclipse/scala.rb?rev=881053&r1=881052&r2=881053&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/ide/eclipse/scala.rb (original)
+++ buildr/trunk/lib/buildr/ide/eclipse/scala.rb Mon Nov 16 23:35:47 2009
@@ -26,14 +26,15 @@
       CONTAINER = 'ch.epfl.lamp.sdt.launching.SCALA_CONTAINER'
       BUILDER   = 'ch.epfl.lamp.sdt.core.scalabuilder'
 
-      after_define do |project|
+      after_define :eclipse => :eclipse_scala
+      after_define :eclipse_scala do |project|
         eclipse = project.eclipse
-
         # smart defaults
         if eclipse.natures.empty? && (project.compile.language == :scala || project.test.compile.language == :scala)
           eclipse.natures = [NATURE, Buildr::Eclipse::Java::NATURE]
           eclipse.classpath_containers = [CONTAINER, Buildr::Eclipse::Java::CONTAINER] if eclipse.classpath_containers.empty?
           eclipse.builders = BUILDER if eclipse.builders.empty?
+          eclipse.exclude_libs += Buildr::Scala::Scalac.dependencies
         end
 
         # :scala nature explicitly set
@@ -54,6 +55,7 @@
             eclipse.builders -= [Buildr::Eclipse::Java::BUILDER]
             eclipse.builders += [BUILDER]
           end
+          eclipse.exclude_libs += Buildr::Scala::Scalac.dependencies
         end
       end
 

Modified: buildr/trunk/spec/ide/eclipse_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/ide/eclipse_spec.rb?rev=881053&r1=881052&r2=881053&view=diff
==============================================================================
--- buildr/trunk/spec/ide/eclipse_spec.rb (original)
+++ buildr/trunk/spec/ide/eclipse_spec.rb Mon Nov 16 23:35:47 2009
@@ -201,7 +201,7 @@
         build_commands.should include(JAVA_BUILDER)
       end
     end
-    
+
     describe 'Plugin project' do
 
       before do
@@ -224,7 +224,7 @@
         build_commands.should include(JAVA_BUILDER)
       end
     end
-    
+
     describe 'Plugin project with META-INF/MANIFEST.MF' do
 
       before do
@@ -236,10 +236,10 @@
         write 'META-INF/MANIFEST.MF', <<-MANIFEST
 Manifest-Version: 1.0
 Name: example/
-Specification-Title: "Examples" 
+Specification-Title: "Examples"
 Specification-Version: "1.0"
 Specification-Vendor: "Acme Corp.".
-Implementation-Title: "example" 
+Implementation-Title: "example"
 Implementation-Version: "build57"
 Implementation-Vendor: "Acme Corp."
 Bundle-SymbolicName: acme.plugin.example
@@ -252,10 +252,10 @@
         write 'META-INF/MANIFEST.MF', <<-MANIFEST
 Manifest-Version: 1.0
 Name: example/
-Specification-Title: "Examples" 
+Specification-Title: "Examples"
 Specification-Version: "1.0"
 Specification-Vendor: "Acme Corp.".
-Implementation-Title: "example" 
+Implementation-Title: "example"
 Implementation-Version: "build57"
 Implementation-Vendor: "Acme Corp."
 MANIFEST
@@ -421,7 +421,7 @@
       write 'lib/some-local.jar'
       define('foo') { compile.using(:javac).with(_('lib/some-local.jar')) }
     end
-    
+
     it 'should have a lib artifact reference in the .classpath file' do
       classpath_xml_elements.collect("classpathentry[@kind='lib']") { |n| n.attributes['path'] }.
         should include('lib/some-local.jar')
@@ -437,7 +437,7 @@
         compile.using(:javac).with(_('../libs/some-local.jar'))
       end
     end
-    
+
     it 'supports generating library paths with classpath variables' do
       classpath_xml_elements.collect("classpathentry[@kind='var']") { |n| n.attributes['path'] }.
         should include('LIBS/some-local.jar')
@@ -449,7 +449,7 @@
       write 'lib/some.class'
       define('foo') { compile.using(:javac).with(_('lib')) }
     end
-    
+
     it 'should have src reference in the .classpath file' do
       classpath_xml_elements.collect("classpathentry[@kind='src']") { |n| n.attributes['path'] }.
         should include('lib')
@@ -576,4 +576,29 @@
       project('foo:bar2').eclipse.classpath_containers.should include('bar2_classpath_containers')
     end
   end
+
+  describe 'exclude_libs' do
+    it 'should support artifacts' do
+      define('foo') do
+        compile.using(:javac).with('com.example:library:jar:2.0')
+        eclipse.exclude_libs += [ artifact('com.example:library:jar:2.0') ]
+      end
+      artifact('com.example:library:jar:2.0') { |task| write task.name }
+
+      task('eclipse').invoke
+      classpath_xml_elements.collect("classpathentry[@kind='var']") { |n| n.attributes['path'] }.
+        should_not include('M2_REPO/com/example/library/2.0/library-2.0.jar')
+    end
+    it 'should support string paths' do
+      define('foo') do
+        compile.using(:javac).with _('path/to/library.jar')
+        eclipse.exclude_libs += [ _('path/to/library.jar') ]
+      end
+      write project('foo').path_to('path/to/library.jar')
+
+      task('eclipse').invoke
+      classpath_xml_elements.collect("classpathentry[@kind='lib']") { |n| n.attributes['path'] }.
+        should_not include('path/to/library.jar')
+    end
+  end
 end