You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by la...@apache.org on 2008/10/23 23:17:26 UTC
svn commit: r707477 - in /incubator/buildr/trunk: CHANGELOG
lib/buildr/packaging/artifact.rb spec/core/compile_spec.rb
spec/packaging/artifact_spec.rb
Author: lacton
Date: Thu Oct 23 14:17:25 2008
New Revision: 707477
URL: http://svn.apache.org/viewvc?rev=707477&view=rev
Log:
BUILDR-164 New 'sources' task to download source code
Modified:
incubator/buildr/trunk/CHANGELOG
incubator/buildr/trunk/lib/buildr/packaging/artifact.rb
incubator/buildr/trunk/spec/core/compile_spec.rb
incubator/buildr/trunk/spec/packaging/artifact_spec.rb
Modified: incubator/buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=707477&r1=707476&r2=707477&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Thu Oct 23 14:17:25 2008
@@ -1,5 +1,7 @@
1.3.4 (Pending)
* Added: BUILDR-159 Improved 'check' to accept both tar and tgz archives.
+* Added: BUILDR-164 New 'sources' task to download source code
+ for artifact jars.
* Change: Introduced new options from Rake 0.8.3: -I (libdir), -R (rakelib),
--rules, --no-search, --silent.
* Changed: Upgraded to Rubyforge 1.0.1.
Modified: incubator/buildr/trunk/lib/buildr/packaging/artifact.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/packaging/artifact.rb?rev=707477&r1=707476&r2=707477&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/packaging/artifact.rb (original)
+++ incubator/buildr/trunk/lib/buildr/packaging/artifact.rb Thu Oct 23 14:17:25 2008
@@ -24,6 +24,9 @@
desc 'Download all artifacts'
task 'artifacts'
+ desc "Download all artifacts' sources"
+ task 'sources'
+
# 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
@@ -110,15 +113,6 @@
end
end
- # :call-seq:
- # sources_artifact => Artifact
- #
- # Convenience method that returns the sources artifact corresponding to this artifact.
- def sources_artifact
- return self if type == :sources
- Buildr.artifact(:group=>group, :id=>id, :version=>version, :type=>:sources)
- end
-
def install
pom.install if pom && pom != self
invoke
@@ -414,6 +408,38 @@
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
+
+ class << self
+
+ # :call-seq:
+ # register_source_artifact_for(spec)
+ #
+ # Register the source artifact corresponding to the provided artifact spec
+ # so that the 'sources' task will try to download it.
+ def register_source_artifact_for(spec)
+ sources_spec = spec.merge(:classifier=>'sources')
+ sources_task = OptionalArtifact.define_task(Buildr.repositories.locate(sources_spec))
+ sources_task.send :apply_spec, sources_spec
+ Rake::Task['sources'].enhance [sources_task]
+ end
+
+ end
+
+ protected
+
+ # If downloading fails, the user will be informed but it will not raise an exception.
+ def download
+ super
+ rescue
+ info "Failed to download #{to_spec}. Skipping it."
+ end
+
+ end
# Holds the path to the local repository, URLs for remote repositories, and settings for release server.
@@ -601,6 +627,7 @@
task.send :apply_spec, spec
Rake::Task['rake:artifacts'].enhance [task]
Artifact.register(task)
+ OptionalArtifact.register_source_artifact_for(spec)
end
task.enhance &block
end
Modified: incubator/buildr/trunk/spec/core/compile_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/core/compile_spec.rb?rev=707477&r1=707476&r2=707477&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/core/compile_spec.rb (original)
+++ incubator/buildr/trunk/spec/core/compile_spec.rb Thu Oct 23 14:17:25 2008
@@ -379,7 +379,7 @@
it 'should complain if source directories and no compiler selected' do
mkpath 'sources'
define 'bar' do
- lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler selected/i)
+ lambda { compile.from(_('sources')).invoke }.should raise_error(RuntimeError, /no compiler selected/i)
end
end
end
Modified: incubator/buildr/trunk/spec/packaging/artifact_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/packaging/artifact_spec.rb?rev=707477&r1=707476&r2=707477&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/packaging/artifact_spec.rb (original)
+++ incubator/buildr/trunk/spec/packaging/artifact_spec.rb Thu Oct 23 14:17:25 2008
@@ -75,10 +75,6 @@
@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(:type=>: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/)
@@ -643,7 +639,32 @@
describe Rake::Task, ' sources' do
- it 'should download all sources'
+
+ before do
+ task('sources').clear
+ repositories.remote = 'http://example.com'
+ artifact 'group:id:jar:1.0'
+ end
+
+ it 'should download sources for all specified artifacts' do
+ URI.should_receive(:download).any_number_of_times.and_return { |uri, target| write target }
+ lambda { task('sources').invoke }.should change { File.exist?('home/.m2/repository/group/id/1.0/id-1.0-sources.jar') }.to(true)
+ end
+
+ describe 'when the source artifact does not exist' do
+
+ before do
+ URI.should_receive(:download).any_number_of_times.and_raise(URI::NotFoundError)
+ end
+
+ it 'should not fail' do
+ lambda { task('sources').invoke }.should_not raise_error
+ end
+
+ it 'should inform the user' do
+ lambda { task('sources').invoke }.should show_info('Failed to download group:id:jar:sources:1.0. Skipping it.')
+ end
+ end
end
Re: svn commit: r707477 - in /incubator/buildr/trunk: CHANGELOG lib/buildr/packaging/artifact.rb spec/core/compile_spec.rb spec/packaging/artifact_spec.rb
Posted by Assaf Arkin <ar...@intalio.com>.
On Sat, Oct 25, 2008 at 9:02 AM, lacton <la...@users.sourceforge.net> wrote:
> On Fri, Oct 24, 2008 at 12:59 AM, Assaf Arkin <ar...@intalio.com> wrote:
>>> Buildr (rake) interpreted "compile.from('sources')" as a dependency to
>>> the new 'sources' task instead of the 'sources' subdirectory.
>>
>> Short term, rename the task to something that's clearly not a
>> file/directory name, say artifact:sources, or download:sources.
>
> Done.
>
>> Long term, this has been bugging me for a while. All tasks share the
>> same name, including file tasks and occasionally we get collisions.
>> There's a work around, using full paths as often as possible, which
>> works most of the time, but brings its own annoyance: console output
>> runs a mile long.
>
> I agree reading absolute paths is annoying. What I'd like is for
> buildr to display paths relative to the project root dir whenever
> possible.
>
> Instead of
> Compiling foo:bar:mail into
> /home/lacton/projects/mycompany/foo/bar/mail/target/classes
> I'd rather have
> Compiling foo:bar:mail into bar/mail/target/classes
>
> For files in the project root dir, we could prefix the path with './'.
> That way, 'sources' would be the task and './sources' would be the
> file task.
I think that would just be confusing. All paths within the project
root should either use './' or not; it's enough to have it different
between project paths and absolute paths.
>> I'd like at some point to truncate these too-long paths, maybe the
>> solution would be to use namespaces for most other tasks?
>
> Do you mean like typing 'buildr buildr:clean buildr:build' instead of
> 'buildr clean build'?
Not every single task, that would just be too much ...
There are some benefits to absolute paths:
- Task files mostly don't conflict with named tasks, or as we found
out, not often enough to be a serious issue.
- It avoids the accidental duplicate; in Rake, file("foo") and
file("./foo") are different tasks even though they point to the same
file.
- You can use them when running rake from the command line, the same
path works in every directory.
- Way back in the past we needed a lot of expand_path in Buildr, and
it was just easier to have _() handle it. (Last because it's no
longer an issue)
Assaf
>
> Lacton
>
>> Assaf
>>
>>>
>>> Any better idea?
>>>
>>> Lacton
>>>
>>>> Modified: incubator/buildr/trunk/spec/core/compile_spec.rb
>>>> URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/core/compile_spec.rb?rev=707477&r1=707476&r2=707477&view=diff
>>>> ==============================================================================
>>>> --- incubator/buildr/trunk/spec/core/compile_spec.rb (original)
>>>> +++ incubator/buildr/trunk/spec/core/compile_spec.rb Thu Oct 23 14:17:25 2008
>>>> @@ -379,7 +379,7 @@
>>>> it 'should complain if source directories and no compiler selected' do
>>>> mkpath 'sources'
>>>> define 'bar' do
>>>> - lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler selected/i)
>>>> + lambda { compile.from(_('sources')).invoke }.should raise_error(RuntimeError, /no compiler selected/i)
>>>> end
>>>> end
>>>> end
>>>
>>
>
Re: svn commit: r707477 - in /incubator/buildr/trunk: CHANGELOG lib/buildr/packaging/artifact.rb spec/core/compile_spec.rb spec/packaging/artifact_spec.rb
Posted by lacton <la...@users.sourceforge.net>.
On Fri, Oct 24, 2008 at 12:59 AM, Assaf Arkin <ar...@intalio.com> wrote:
>> Buildr (rake) interpreted "compile.from('sources')" as a dependency to
>> the new 'sources' task instead of the 'sources' subdirectory.
>
> Short term, rename the task to something that's clearly not a
> file/directory name, say artifact:sources, or download:sources.
Done.
> Long term, this has been bugging me for a while. All tasks share the
> same name, including file tasks and occasionally we get collisions.
> There's a work around, using full paths as often as possible, which
> works most of the time, but brings its own annoyance: console output
> runs a mile long.
I agree reading absolute paths is annoying. What I'd like is for
buildr to display paths relative to the project root dir whenever
possible.
Instead of
Compiling foo:bar:mail into
/home/lacton/projects/mycompany/foo/bar/mail/target/classes
I'd rather have
Compiling foo:bar:mail into bar/mail/target/classes
For files in the project root dir, we could prefix the path with './'.
That way, 'sources' would be the task and './sources' would be the
file task.
> I'd like at some point to truncate these too-long paths, maybe the
> solution would be to use namespaces for most other tasks?
Do you mean like typing 'buildr buildr:clean buildr:build' instead of
'buildr clean build'?
Lacton
> Assaf
>
>>
>> Any better idea?
>>
>> Lacton
>>
>>> Modified: incubator/buildr/trunk/spec/core/compile_spec.rb
>>> URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/core/compile_spec.rb?rev=707477&r1=707476&r2=707477&view=diff
>>> ==============================================================================
>>> --- incubator/buildr/trunk/spec/core/compile_spec.rb (original)
>>> +++ incubator/buildr/trunk/spec/core/compile_spec.rb Thu Oct 23 14:17:25 2008
>>> @@ -379,7 +379,7 @@
>>> it 'should complain if source directories and no compiler selected' do
>>> mkpath 'sources'
>>> define 'bar' do
>>> - lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler selected/i)
>>> + lambda { compile.from(_('sources')).invoke }.should raise_error(RuntimeError, /no compiler selected/i)
>>> end
>>> end
>>> end
>>
>
Re: svn commit: r707477 - in /incubator/buildr/trunk: CHANGELOG lib/buildr/packaging/artifact.rb spec/core/compile_spec.rb spec/packaging/artifact_spec.rb
Posted by Assaf Arkin <ar...@intalio.com>.
On Thu, Oct 23, 2008 at 2:22 PM, lacton <la...@users.sourceforge.net> wrote:
> You may have noticed that I changed compile_spec after adding the
> 'sources' task for BUILDR-164.
>
> Buildr (rake) interpreted "compile.from('sources')" as a dependency to
> the new 'sources' task instead of the 'sources' subdirectory.
Short term, rename the task to something that's clearly not a
file/directory name, say artifact:sources, or download:sources.
Long term, this has been bugging me for a while. All tasks share the
same name, including file tasks and occasionally we get collisions.
There's a work around, using full paths as often as possible, which
works most of the time, but brings its own annoyance: console output
runs a mile long.
I'd like at some point to truncate these too-long paths, maybe the
solution would be to use namespaces for most other tasks?
Assaf
>
> Any better idea?
>
> Lacton
>
>> Modified: incubator/buildr/trunk/spec/core/compile_spec.rb
>> URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/core/compile_spec.rb?rev=707477&r1=707476&r2=707477&view=diff
>> ==============================================================================
>> --- incubator/buildr/trunk/spec/core/compile_spec.rb (original)
>> +++ incubator/buildr/trunk/spec/core/compile_spec.rb Thu Oct 23 14:17:25 2008
>> @@ -379,7 +379,7 @@
>> it 'should complain if source directories and no compiler selected' do
>> mkpath 'sources'
>> define 'bar' do
>> - lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler selected/i)
>> + lambda { compile.from(_('sources')).invoke }.should raise_error(RuntimeError, /no compiler selected/i)
>> end
>> end
>> end
>
Re: svn commit: r707477 - in /incubator/buildr/trunk: CHANGELOG lib/buildr/packaging/artifact.rb spec/core/compile_spec.rb spec/packaging/artifact_spec.rb
Posted by lacton <la...@users.sourceforge.net>.
You may have noticed that I changed compile_spec after adding the
'sources' task for BUILDR-164.
Buildr (rake) interpreted "compile.from('sources')" as a dependency to
the new 'sources' task instead of the 'sources' subdirectory.
Any better idea?
Lacton
> Modified: incubator/buildr/trunk/spec/core/compile_spec.rb
> URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/core/compile_spec.rb?rev=707477&r1=707476&r2=707477&view=diff
> ==============================================================================
> --- incubator/buildr/trunk/spec/core/compile_spec.rb (original)
> +++ incubator/buildr/trunk/spec/core/compile_spec.rb Thu Oct 23 14:17:25 2008
> @@ -379,7 +379,7 @@
> it 'should complain if source directories and no compiler selected' do
> mkpath 'sources'
> define 'bar' do
> - lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler selected/i)
> + lambda { compile.from(_('sources')).invoke }.should raise_error(RuntimeError, /no compiler selected/i)
> end
> end
> end