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 2010/03/01 18:59:47 UTC

svn commit: r917616 - in /buildr/trunk: CHANGELOG lib/buildr/packaging/artifact.rb spec/packaging/artifact_spec.rb

Author: boisvert
Date: Mon Mar  1 17:59:46 2010
New Revision: 917616

URL: http://svn.apache.org/viewvc?rev=917616&view=rev
Log:
BUILDR-390 Buildr::group() should accept :classifier argument

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

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=917616&r1=917615&r2=917616&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Mon Mar  1 17:59:46 2010
@@ -21,6 +21,7 @@
 * Added:  BUILDR-326 Support unzipping tar.gz files (Antoine Toulme)
 * Added:  BUILDR-375 Buildr now recognizes buildfile.rb and Buildfile.rb
           (Kerry Wilson)
+* Added:  BUILDR-390 Buildr::group() should accept :classifier argument
 * Change: Updated to Ant 1.8.0
 * Change: Updated to JRuby 1.4.0
 * Change: Updated to JtestR 0.5

Modified: buildr/trunk/lib/buildr/packaging/artifact.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/packaging/artifact.rb?rev=917616&r1=917615&r2=917616&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/packaging/artifact.rb (original)
+++ buildr/trunk/lib/buildr/packaging/artifact.rb Mon Mar  1 17:59:46 2010
@@ -90,7 +90,7 @@
 
     # :call-seq:
     #   pom => Artifact
-    # 
+    #
     # Convenience method that returns a POM artifact.
     def pom
       return self if type == :pom
@@ -99,7 +99,7 @@
 
     # :call-seq:
     #   sources_artifact => Artifact
-    # 
+    #
     # Convenience method that returns a sources artifact.
     def sources_artifact
       sources_spec = to_spec_hash.merge(:classifier=>'sources')
@@ -123,7 +123,7 @@
         xml.classifier    classifier if classifier
       end
     end
-    
+
     def install
       pom.install if pom && pom != self
       invoke
@@ -137,7 +137,7 @@
 
     def uninstall
       installed = Buildr.repositories.locate(self)
-      rm installed if File.exist?(installed) 
+      rm installed if File.exist?(installed)
       pom.uninstall if pom && pom != self
     end
 
@@ -183,14 +183,14 @@
       ARTIFACT_ATTRIBUTES.each { |key| instance_variable_set("@#{key}", spec[key]) }
       self
     end
-    
+
     def group_path
       group.gsub('.', '/')
     end
 
   end
 
- 
+
   # A file task referencing an artifact in the local repository.
   #
   # This task includes all the artifact attributes (group, id, version, etc). It points
@@ -329,7 +329,7 @@
           path = File.expand_path(path.to_s)
           mkpath File.dirname(name)
           pom.invoke unless type == :pom
-          
+
           cp path, name
           info "Installed #{path} as #{to_spec}"
         end
@@ -349,7 +349,7 @@
 
     # :call-seq:
     #   download
-    # 
+    #
     # Downloads an artifact from one of the remote repositories, and stores it in the local
     # repository. Raises an exception if the artifact is not found.
     #
@@ -417,21 +417,21 @@
       fail "Failed to download #{to_spec}, tried the following repositories:\n#{remote_uris.join("\n")}"
     end
   end
-  
-  
+
+
   # An artifact that is optional.
   # If downloading fails, the user will be informed but it will not raise an exception.
   class OptionalArtifact < Artifact
-    
+
     protected
-    
+
     # If downloading fails, the user will be informed but it will not raise an exception.
     def download
       super
-    rescue 
+    rescue
       info "Failed to download #{to_spec}. Skipping it."
     end
-    
+
   end
 
 
@@ -464,8 +464,8 @@
     # Sets the path to the local repository.
     #
     # The best place to set the local repository path is from a buildr.rb file
-    # located in the .buildr directory under your home directory. That way all 
-    # your projects will share the same path, without affecting other developers 
+    # located in the .buildr directory under your home directory. That way all
+    # your projects will share the same path, without affecting other developers
     # collaborating on these projects.
     def local=(dir)
       @local = dir ? File.expand_path(dir) : nil
@@ -704,6 +704,7 @@
   # * :under -- The group identifier
   # * :version -- The version number
   # * :type -- The artifact type (optional)
+  # * :classifier -- The artifact classifier (optional)
   #
   # For example:
   #   group 'xbean', 'xbean_xpath', 'xmlpublic', :under=>'xmlbeans', :version=>'2.1.0'
@@ -711,8 +712,14 @@
   #   group %w{xbean xbean_xpath xmlpublic}, :under=>'xmlbeans', :version=>'2.1.0'
   def group(*args)
     hash = args.pop
-    args.flatten.map { |id| artifact :group=>hash[:under], :type=>hash[:type], :version=>hash[:version], :id=>id }
-  end 
+    args.flatten.map do |id|
+      artifact :group   => hash[:under],
+               :type    => hash[:type],
+               :version => hash[:version],
+               :classifier => hash[:classifier],
+               :id => id
+    end
+  end
 
   # :call-seq:
   #   install(artifacts)

Modified: buildr/trunk/spec/packaging/artifact_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/packaging/artifact_spec.rb?rev=917616&r1=917615&r2=917616&view=diff
==============================================================================
--- buildr/trunk/spec/packaging/artifact_spec.rb (original)
+++ buildr/trunk/spec/packaging/artifact_spec.rb Mon Mar  1 17:59:46 2010
@@ -74,11 +74,11 @@
   it 'should have one POM artifact for all classifiers' do
     @classified.pom.to_hash.should == @classified.to_hash.merge(:type=>:pom).except(:classifier)
   end
-  
+
   it 'should have associated sources artifact' do
     @artifact.sources_artifact.to_hash.should == @artifact.to_hash.merge(:classifier=>'sources')
   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/)
@@ -112,7 +112,7 @@
   end
 
   it 'should not download file if dry-run' do
-    dryrun do 
+    dryrun do
       lambda { @artifact.invoke }.should_not raise_error
       lambda { @classified.invoke }.should_not raise_error
     end
@@ -243,7 +243,7 @@
     artifact('group:id:jar:1.0').invoke
     uri.to_s.should eql('http://example.com/base/group/id/1.0/id-1.0.pom')
   end
-  
+
   it 'should resolve m2-style deployed snapshots' do
     metadata = <<-XML
     <?xml version='1.0' encoding='UTF-8'?>
@@ -270,7 +270,7 @@
     lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.
       should change { File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')) }.to(true)
   end
-  
+
   it 'should handle missing maven metadata by reporting the artifact unavailable' do
     repositories.remote = 'http://example.com'
     URI.should_receive(:download).with(uri(/2.1-SNAPSHOT\/library-2.1-SNAPSHOT.jar$/), anything()).
@@ -280,7 +280,7 @@
     lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.should raise_error(RuntimeError, /Failed to download/)
     File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')).should be_false
   end
-  
+
   it 'should handle missing m2 snapshots by reporting the artifact unavailable' do
     metadata = <<-XML
     <?xml version='1.0' encoding='UTF-8'?>
@@ -399,7 +399,7 @@
   it 'should complain about invalid key' do
     lambda { artifact(@spec.merge(:error=>true)) }.should raise_error(ArgumentError, /no such option/i)
   end
-  
+
   it 'should use JAR type by default' do
     artifact(@spec.merge(:type=>nil)).should respond_to(:invoke)
   end
@@ -409,7 +409,7 @@
   end
 
   it 'should reject partial string specifier' do
-    artifact('com.example:library::2.0') 
+    artifact('com.example:library::2.0')
     lambda { artifact('com.example:library:jar') }.should raise_error
     lambda { artifact('com.example:library:jar:') }.should raise_error
     lambda { artifact('com.example:library::2.0') }.should_not raise_error
@@ -428,7 +428,7 @@
     artifact = artifact('group:id:jar:1.0').from('test.jar')
     lambda { artifact.invoke }.should change { File.exist?(artifact.to_s) }.to(true)
   end
-  
+
   it 'should use from method to install artifact from a file task' do
     test_jar = file('test.jar')
     test_jar.enhance do
@@ -438,7 +438,7 @@
     artifact = artifact('group:id:jar:1.0').from(test_jar)
     lambda { artifact.invoke }.should change { File.exist?(artifact.to_s) }.to(true)
   end
-  
+
   it 'should invoke the artifact associated file task if the file doesnt exist' do
     test_jar = file('test.jar')
     called = false
@@ -448,11 +448,11 @@
     end
     artifact = artifact('group:id:jar:1.0').from(test_jar)
     artifact.invoke
-    unless called 
+    unless called
       raise "The file task was not called."
     end
   end
-  
+
   it 'should not invoke the artifact associated file task if the file already exists' do
     test_jar = file('test.jar')
     test_jar.enhance do
@@ -465,7 +465,7 @@
 
   it 'should reference artifacts defined on build.yaml by using ruby symbols' do
     write 'build.yaml', <<-YAML
-      artifacts: 
+      artifacts:
         j2ee: geronimo-spec:geronimo-spec-j2ee:jar:1.4-rc4
     YAML
     Buildr.application.send(:load_artifact_ns)
@@ -541,14 +541,20 @@
     list.should include(artifact('saxon:saxon-xpath:jar:8.4'))
     list.size.should be(3)
   end
-  
+
   it 'should accept a type' do
     list = group('struts-bean', 'struts-html', :under=>'struts', :type=>'tld', :version=>'1.1')
     list.should include(artifact('struts:struts-bean:tld:1.1'))
     list.should include(artifact('struts:struts-html:tld:1.1'))
     list.size.should be(2)
   end
-  
+
+  it 'should accept a classifier' do
+    list = group('camel-core', :under=>'org.apache.camel', :version=>'2.2.0', :classifier=>'spring3')
+    list.should include(artifact('org.apache.camel:camel-core:jar:spring3:2.2.0'))
+    list.size.should be(1)
+  end
+
 end
 
 describe Buildr, '#install' do
@@ -575,7 +581,7 @@
   it 'should re-install artifact when "from" is newer' do
     install artifact(@spec).from(@file)
     write artifact(@spec).to_s # install a version of the artifact
-    sleep 1; write @file       # make sure the "from" file has newer modification time 
+    sleep 1; write @file       # make sure the "from" file has newer modification time
     lambda { install.invoke }.should change { File.exist?(artifact(@spec).to_s) and File.mtime(@file) == File.mtime(artifact(@spec).to_s) }.to(true)
   end
 
@@ -689,30 +695,30 @@
     task('artifacts:sources').clear
     repositories.remote = 'http://example.com'
   end
-  
+
   it 'should download sources 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:sources').invoke }.should change { File.exist?('home/.m2/repository/group/id/1.0/id-1.0-sources.jar') }.to(true)
   end
-  
+
   it "should not try to download sources for the project's artifacts" do
     define('foo', :version=>'1.0') { package(:jar) }
     URI.should_not_receive(:download)
     task('artifacts:sources').invoke
   end
-  
+
   describe 'when the source 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:sources').invoke }.should_not raise_error
     end
-    
+
     it 'should inform the user' do
       lambda { task('artifacts:sources').invoke }.should show_info('Failed to download group:id:jar:sources:1.0. Skipping it.')
     end