buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From boisv...@apache.org
Subject svn commit: r998519 - in /buildr/trunk: CHANGELOG lib/buildr/ide/eclipse.rb lib/buildr/packaging/artifact.rb spec/ide/eclipse_spec.rb spec/packaging/artifact_spec.rb
Date Sat, 18 Sep 2010 18:50:46 GMT
Author: boisvert
Date: Sat Sep 18 18:50:46 2010
New Revision: 998519

URL: http://svn.apache.org/viewvc?rev=998519&view=rev
Log:
BUILDR-493 Eclipse task should generate javadocpath

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

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=998519&r1=998518&r2=998519&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Sat Sep 18 18:50:46 2010
@@ -3,6 +3,7 @@
 * Added:  BUILDR-495 Document twitter on Buildr's homepage
 * Added:  BUILDR-212 Update support for SNAPSHOT artifacts (Timo Rantalaiho and Izzet Mustafa)
 * Added:  BUILDR-465 Eclipse project names should be customizable
+* Added:  BUILDR-493 Eclipse task should generate javadocpath
 * Added:  BUILDR-509 Option to generate non-prefixed Eclipse project names
 * Added:  Integration test to show how to change the war packaging spec.
 * Added:  Integration test to show how to use junit 3.

Modified: buildr/trunk/lib/buildr/ide/eclipse.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/ide/eclipse.rb?rev=998519&r1=998518&r2=998519&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/ide/eclipse.rb (original)
+++ buildr/trunk/lib/buildr/ide/eclipse.rb Sat Sep 18 18:50:46 2010
@@ -358,18 +358,27 @@ module Buildr
       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.to_s)
+          
+          attribs = { :kind => 'var', :path => lib_path }
+          
           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
+            attribs[:sourcepath] = lib_artifact.sources_artifact
           end
+          
+          if lib_artifact.respond_to? :javadoc_artifact
+            attribs[:javadocpath] = lib_artifact.javadoc_artifact
+          end
+          
+          # make all paths relative
+          attribs.each_key do |k|
+            attribs[k] = attribs[k].to_s.sub(var_value, var_name.to_s) if k.to_s =~ /path/
+          end
+
+          @xml.classpathentry attribs
         end
       end
 
-      private
+    private
 
       # Find a path relative to the project's root directory if possible. If the
       # two paths do not share the same root the absolute path is returned. This

Modified: buildr/trunk/lib/buildr/packaging/artifact.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/packaging/artifact.rb?rev=998519&r1=998518&r2=998519&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/packaging/artifact.rb (original)
+++ buildr/trunk/lib/buildr/packaging/artifact.rb Sat Sep 18 18:50:46 2010
@@ -28,6 +28,9 @@ module Buildr
   desc "Download all artifacts' sources"
   task 'artifacts:sources'
 
+  desc "Download all artifacts' javadoc"
+  task 'artifacts:javadoc'
+
   # Mixin with a task to make it behave like an artifact. Implemented by the packaging tasks.
   #
   # An artifact has an identifier, group identifier, type, version number and
@@ -128,6 +131,17 @@ module Buildr
     end
 
     # :call-seq:
+    #   javadoc_artifact => Artifact
+    #
+    # Convenience method that returns the associated javadoc artifact
+    def javadoc_artifact
+      javadoc_spec = to_spec_hash.merge(:classifier=>'javadoc')
+      javadoc_task = OptionalArtifact.define_task(Buildr.repositories.locate(javadoc_spec))
+      javadoc_task.send :apply_spec, javadoc_spec
+      javadoc_task
+    end
+
+    # :call-seq:
     #   pom_xml => string
     #
     # Creates POM XML for this artifact.
@@ -742,7 +756,10 @@ module Buildr
       task.send :apply_spec, spec
       Rake::Task['rake:artifacts'].enhance [task]
       Artifact.register(task)
-      Rake::Task['artifacts:sources'].enhance [task.sources_artifact] unless spec[:type]
== :pom
+      unless spec[:type] == :pom
+        Rake::Task['artifacts:sources'].enhance [task.sources_artifact] 
+        Rake::Task['artifacts:javadoc'].enhance [task.javadoc_artifact]
+      end
     end
     task.enhance &block
   end

Modified: buildr/trunk/spec/ide/eclipse_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/ide/eclipse_spec.rb?rev=998519&r1=998518&r2=998519&view=diff
==============================================================================
--- buildr/trunk/spec/ide/eclipse_spec.rb (original)
+++ buildr/trunk/spec/ide/eclipse_spec.rb Sat Sep 18 18:50:46 2010
@@ -61,6 +61,13 @@ module EclipseHelper
     end
   end
 
+  # <classpathentry path="PATH" javadocpath="RETURNED_VALUE" kind="var"/>
+  def javadocpath_for_path(path)
+    classpath_xml_elements.collect("classpathentry[@kind='var',@path='#{path}']") do |n|
+      n.attributes['javadocpath'] || 'no javadoc artifact'
+    end
+  end
+
   def project_xml_elements
     task('eclipse').invoke
     File.open('.project') { |f| REXML::Document.new(f).root.elements }
@@ -578,6 +585,11 @@ MANIFEST
       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
+
+    it 'should have a javadoc artifact reference in the .classpath file' do
+      javadocpath_for_path('M2_REPO/com/example/library/2.0/library-2.0.jar').
+        should == ['M2_REPO/com/example/library/2.0/library-2.0-javadoc.jar']
+    end
   end
 
   describe 'maven2 repository variable' do

Modified: buildr/trunk/spec/packaging/artifact_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/packaging/artifact_spec.rb?rev=998519&r1=998518&r2=998519&view=diff
==============================================================================
--- buildr/trunk/spec/packaging/artifact_spec.rb (original)
+++ buildr/trunk/spec/packaging/artifact_spec.rb Sat Sep 18 18:50:46 2010
@@ -79,6 +79,10 @@ describe Artifact do
     @artifact.sources_artifact.to_hash.should == @artifact.to_hash.merge(:classifier=>'sources')
   end
 
+  it 'should have associated javadoc artifact' do
+    @artifact.javadoc_artifact.to_hash.should == @artifact.to_hash.merge(:classifier=>'javadoc')
+  end
+
   it 'should download file if file does not exist' do
     lambda { @artifact.invoke }.should raise_error(Exception, /No remote repositories/)
     lambda { @classified.invoke }.should raise_error(Exception, /No remote repositories/)
@@ -890,6 +894,41 @@ describe Rake::Task, ' artifacts:sources
   end
 end
 
+describe Rake::Task, ' artifacts:javadoc' do
+
+  before do
+    task('artifacts:javadoc').clear
+    repositories.remote = 'http://example.com'
+  end
+
+  it 'should download javadoc for all specified artifacts' do
+    artifact 'group:id:jar:1.0'
+    URI.should_receive(:download).any_number_of_times.and_return { |uri, target| write target
}
+    lambda { task('artifacts:javadoc').invoke }.should change { File.exist?('home/.m2/repository/group/id/1.0/id-1.0-javadoc.jar')
}.to(true)
+  end
+
+  it "should not try to download javadoc for the project's artifacts" do
+    define('foo', :version=>'1.0') { package(:jar) }
+    URI.should_not_receive(:download)
+    task('artifacts:javadoc').invoke
+  end
+
+  describe 'when the javadoc artifact does not exist' do
+
+    before do
+      artifact 'group:id:jar:1.0'
+      URI.should_receive(:download).any_number_of_times.and_raise(URI::NotFoundError)
+    end
+
+    it 'should not fail' do
+      lambda { task('artifacts:javadoc').invoke }.should_not raise_error
+    end
+
+    it 'should inform the user' do
+      lambda { task('artifacts:javadoc').invoke }.should show_info('Failed to download group:id:jar:javadoc:1.0.
Skipping it.')
+    end
+  end
+end
 
 describe Buildr, '#transitive' do
   before do



Mime
View raw message