Author: assaf
Date: Tue Mar 25 21:50:54 2008
New Revision: 641147
URL: http://svn.apache.org/viewvc?rev=641147&view=rev
Log:
BUILDR-55
Added:
incubator/buildr/trunk/lib/core/filter.rb
Removed:
incubator/buildr/trunk/etc/legal/facets-LICENSE.txt
Modified:
incubator/buildr/trunk/CHANGELOG
incubator/buildr/trunk/NOTICE
incubator/buildr/trunk/Rakefile
incubator/buildr/trunk/doc/pages/whats_new.textile
incubator/buildr/trunk/lib/buildr.rb
incubator/buildr/trunk/lib/core.rb
incubator/buildr/trunk/lib/core/checks.rb
incubator/buildr/trunk/lib/core/common.rb
incubator/buildr/trunk/lib/core/compile.rb
incubator/buildr/trunk/lib/core/project.rb
incubator/buildr/trunk/lib/core/transports.rb
incubator/buildr/trunk/lib/java/artifact.rb
incubator/buildr/trunk/lib/java/packaging.rb
incubator/buildr/trunk/lib/java/pom.rb
incubator/buildr/trunk/lib/tasks/zip.rb
incubator/buildr/trunk/spec/addon_spec.rb
incubator/buildr/trunk/spec/artifact_spec.rb
incubator/buildr/trunk/spec/project_spec.rb
incubator/buildr/trunk/spec/spec_helpers.rb
Modified: incubator/buildr/trunk/CHANGELOG
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Tue Mar 25 21:50:54 2008
@@ -17,7 +17,7 @@
* Added: Experimental support for addons.
* Changed: JUnit/TestNG test cases are selected by superClass or annotations,
not by class-name pattern.
* Changed: Upgraded to Antwrap 0.7.0, thanks to Caleb Powell for relicensing
under Apache License.
-* Changed: Upgraded to Rake 0.8, RSpec 1.1, RJB 1.1, Facets 2.2, OpenJPA 1.0.1.
+* Changed: Upgraded to Rake 0.8, RSpec 1.1, RJB 1.1, OpenJPA 1.0.1.
* Changed: Resources are now copied to target/resources instead of
target/classes, and target/test/resources instead of target/test-resources.
* Changed: Test cases are now compiled into target/test/classes instead of
target/test-classes.
* Changed: Compile extension and CompileTask are now separate from the Java
module. Multiple compilers can be used, either guessed from the project
layout, or specified with compile.using(:name).
@@ -32,6 +32,7 @@
* Changed: Resource tasks no longer generate target directory if there are no
resources to copy over.
* Removed: Prepare tasks removed.
* Removed: All deprecated features since 1.1. If you've seen warnings before,
except the build to break.
+* Removed: No longer using Facets or recommending you use it in buildfiles.
* Fixed: More typos/documentation fixes by Lacton
* Fixed: Artifact.pom resolves artifact without classifier, i.e
org.testng:testng:jar:jdk15:5.1 uses org.testng:testng:pom:5.1 (Tommy).
* Fixed: More patches towards JRuby support, courtesy of Vic Borja.
Modified: incubator/buildr/trunk/NOTICE
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/NOTICE?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/NOTICE (original)
+++ incubator/buildr/trunk/NOTICE Tue Mar 25 21:50:54 2008
@@ -25,10 +25,6 @@
Licensed under MIT/X Consortium
Copyright 2003, 2004 by Jim Weirich.
-* Facets - http://rubyforge.org/projects/facets
-Licensed under the Ruby License
-Copyright 2005,2006,2007 Thomas Sawyer
-
* Builder - http://rubyforge.org/projects/builder
Licensed under MIT/X Consortium
Copyright 2004 by Jim Weirich ([EMAIL PROTECTED]).
@@ -63,6 +59,11 @@
* ruwiki (archive-tar-minitar) - http://rubyforge.org/projects/ruwiki/
Licensed under the Ruby License
Copyright 2004 Mauricio Julio Fernández Pradier and Austin Ziegler
+
+* progressbar - http://0xcc.net/ruby-progressbar/
+Licensed under the Ruby License
+Copyright (C) 2001 Satoru Takabayashi <[EMAIL PROTECTED]>
+
MATERIALS IN DOCUMENTATION
--------------------------
Modified: incubator/buildr/trunk/Rakefile
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/Rakefile?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/Rakefile (original)
+++ incubator/buildr/trunk/Rakefile Tue Mar 25 21:50:54 2008
@@ -2,7 +2,6 @@
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'spec/rake/spectask'
-gem 'facets', '= 2.3.0'
# Gem specification comes first, other tasks rely on it.
@@ -29,7 +28,6 @@
# Tested against these dependencies.
spec.add_dependency 'rake', '~> 0.8'
- spec.add_dependency 'facets', '~> 2.2'
spec.add_dependency 'builder', '~> 2.1'
spec.add_dependency 'net-ssh', '~> 1.1'
spec.add_dependency 'net-sftp', '~> 1.1'
@@ -40,6 +38,7 @@
spec.add_dependency 'xml-simple', '~> 1.0'
spec.add_dependency 'archive-tar-minitar', '~> 0.5'
spec.add_dependency 'rubyforge', '~> 0.4'
+ spec.add_dependency 'progressbar', '~> 0.0.3'
spec.platform = platform
spec.add_dependency 'rjb', '~> 1.1' unless platform == 'java'
@@ -100,6 +99,12 @@
#each { |dep| install_gem dep.name, :version=>dep.version_requirements }
end
+begin
+ require 'highline/import'
+rescue LoadError
+ puts 'HighLine required, please run rake setup first'
+end
+
# Packaging and local installation.
#
desc 'Clean up all temporary directories used for running tests, creating
documentation, packaging, etc.'
@@ -113,8 +118,9 @@
desc 'Uninstall previously installed packaged'
task 'uninstall' do |task|
- say "Uninstalling #{ruby_spec.name} ... "
- ruby 'install', name_or_path.to_s, :command=>'gem', :sudo=>true
+ spec = RUBY_PLATFORM =~ /java/ ? jruby_spec : ruby_spec
+ say "Uninstalling #{spec.name} ... "
+ ruby 'install', spec.name, :command=>'gem', :sudo=>true
say 'Done'
end
@@ -227,14 +233,6 @@
namespace 'release' do
- begin
- require 'highline'
- require 'highline/import'
- Kernel.def_delegators :$terminal, :color
- rescue LoadError
- puts 'HighLine required, please run rake setup first'
- end
-
# This task does all prerequisites checks before starting the release, for
example,
# that we have Groovy and Scala to run all the test cases, or that we have
Allison
# and PrinceXML to generate the full documentation.
Modified: incubator/buildr/trunk/doc/pages/whats_new.textile
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/pages/whats_new.textile?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/pages/whats_new.textile (original)
+++ incubator/buildr/trunk/doc/pages/whats_new.textile Tue Mar 25 21:50:54 2008
@@ -214,8 +214,8 @@
h4. Other
-* Buildr 1.3 upgrades to Rake 0.8, RSpec 1.1, RJB 1.1, Facets 2.2 and OpenJPA
-1.0.1.
+* Buildr 1.3 upgrades to Rake 0.8, RSpec 1.1, RJB 1.1 and OpenJPA
+1.0.1. Buildr no longer includes or uses Facets.
* JUnit tests now operate on all compiled test classes that extend
@junit.framework.TestCase@ or use the @Test@ annotation; TestNG test cases are
Modified: incubator/buildr/trunk/lib/buildr.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr.rb (original)
+++ incubator/buildr/trunk/lib/buildr.rb Tue Mar 25 21:50:54 2008
@@ -22,14 +22,6 @@
require 'highline'
require 'highline/import'
-require 'symbol/to_proc'
-require 'facets/string/blank'
-require 'facets/module/alias_method_chain'
-require 'facets/string/starts_with'
-require 'facets/openobject'
-require 'facets/kernel/tap'
-require 'facets/kernel/ergo'
-require 'facets/enumerable/uniq_by'
require 'builder' # A different kind of buildr, one we use to create XML.
Modified: incubator/buildr/trunk/lib/core.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core.rb (original)
+++ incubator/buildr/trunk/lib/core.rb Tue Mar 25 21:50:54 2008
@@ -20,6 +20,7 @@
require 'core/help'
require 'core/build'
require 'core/package'
+require 'core/filter'
require 'core/compile'
require 'core/test'
require 'core/checks'
Modified: incubator/buildr/trunk/lib/core/checks.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/checks.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/checks.rb (original)
+++ incubator/buildr/trunk/lib/core/checks.rb Tue Mar 25 21:50:54 2008
@@ -330,7 +330,7 @@
def entries() #:nodoc:
return root.entries unless @path
@entries ||= root.entries.inject([]) { |selected, entry|
- selected << entry.name.sub(@path, "") if entry.name.starts_with?(@path)
+ selected << entry.name.sub(@path, "") if entry.name.index(@path) == 0
selected
}
end
Modified: incubator/buildr/trunk/lib/core/common.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/common.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/common.rb (original)
+++ incubator/buildr/trunk/lib/core/common.rb Tue Mar 25 21:50:54 2008
@@ -21,6 +21,24 @@
require 'uri/open-sftp'
require 'rbconfig'
+
+module Kernel #:nodoc:
+ # Borrowed from Ruby 1.9.
+ def tap
+ yield self if block_given?
+ self
+ end unless method_defined?('tap')
+end
+
+
+class Symbol #:nodoc:
+ # Borrowed from Ruby 1.9.
+ def to_proc
+ Proc.new{|*args| args.shift.__send__(self, *args)}
+ end unless method_defined?('to_proc')
+end
+
+
class File
class << self
@@ -46,6 +64,7 @@
end
end
+
class Hash
class << self
@@ -144,6 +163,47 @@
end
+# Also borrowed from Ruby 1.9.
+class BasicObject #:nodoc:
+ (instance_methods - ['__send__', '__id__', '==', 'send', 'send!',
'respond_to?', 'equal?', 'object_id']).
+ each do |method|
+ undef_method method
+ end
+
+ def self.ancestors
+ [Kernel]
+ end
+end
+
+
+class OpenObject < BasicObject
+ def initialize(hash = nil, &block)
+ @hash = Hash.new(&block)
+ @hash.update(hash) if hash
+ end
+
+ def method_missing(symbol, *args)
+ if symbol.to_s =~ /=$/
+ self[symbol.to_s[0..-2].to_sym] = args.first
+ else
+ self[symbol]
+ end
+ end
+
+ def []=(key, value)
+ @hash[key] = value
+ end
+
+ def [](key)
+ @hash[key]
+ end
+
+ def to_hash
+ @hash.clone
+ end
+end
+
+
module Buildr
# :call-seq:
@@ -241,247 +301,6 @@
end
-
- # A filter knows how to copy files from one directory to another, applying
mappings to the
- # contents of these files.
- #
- # You can specify the mapping using a Hash, and it will map ${key} fields
found in each source
- # file into the appropriate value in the target file. For example:
- #
- # filter.using 'version'=>'1.2', 'build'=>Time.now
- #
- # will replace all occurrences of <tt>${version}</tt> with <tt>1.2</tt>, and
<tt>${build}</tt>
- # with the current date/time.
- #
- # You can also specify the mapping by passing a proc or a method, that will
be called for
- # each source file, with the file name and content, returning the modified
content.
- #
- # Without any mapping, the filter simply copies files from the source
directory into the target
- # directory.
- #
- # A filter has one target directory, but you can specify any number of
source directories,
- # either when creating the filter or calling #from. Include/exclude patterns
are specified
- # relative to the source directories, so:
- # filter.include '*.png'
- # will only include PNG files from any of the source directories.
- #
- # See Buildr#filter.
- class Filter
-
- def initialize #:nodoc:
- clear
- end
-
- # Returns the list of source directories (each being a file task).
- attr_reader :sources
-
- # :call-seq:
- # clear => self
- #
- # Clear filter sources and include/exclude patterns
- def clear
- @include = []
- @exclude = []
- @sources = []
- self
- end
-
- # :call-seq:
- # from(*sources) => self
- #
- # Adds additional directories from which to copy resources.
- #
- # For example:
- # filter.from('src').into('target').using('build'=>Time.now)
- def from(*sources)
- @sources |= sources.flatten.map { |dir| file(File.expand_path(dir.to_s))
}
- self
- end
-
- # The target directory as a file task.
- attr_reader :target
-
- # :call-seq:
- # into(dir) => self
- #
- # Sets the target directory into which files are copied and returns self.
- #
- # For example:
- # filter.from('src').into('target').using('build'=>Time.now)
- def into(dir)
- @target = file(File.expand_path(dir.to_s)) { |task| run if target ==
task && !sources.empty? }
- self
- end
-
- # :call-seq:
- # include(*files) => self
- #
- # Specifies files to include and returns self. See FileList#include.
- #
- # By default all files are included. You can use this method to only
include specific
- # files form the source directory.
- def include(*files)
- @include += files
- self
- end
- alias :add :include
-
- # :call-seq:
- # exclude(*files) => self
- #
- # Specifies files to exclude and returns self. See FileList#exclude.
- def exclude(*files)
- @exclude += files
- self
- end
-
- # The mapping. See #using.
- attr_accessor :mapping
-
- # The mapper to use. See #using.
- attr_accessor :mapper
-
- # :call-seq:
- # using(mapping) => self
- # using { |file_name, contents| ... } => self
- #
- # Specifies the mapping to use and returns self.
- #
- # The most typical mapping uses a Hash, and the default mapping uses the
Maven style, so
- # <code>${key}</code> are mapped to the values. You can change that by
passing a different
- # format as the first argument. Currently supports:
- # * :ant -- Map <code>@key@</code>.
- # * :maven -- Map <code>${key}</code> (default).
- # * :ruby -- Map <code>#{key}</code>.
- # * Regexp -- Maps the matched data (e.g. <code>/=(.*?)=/</code>
- #
- # For example:
- # filter.using 'version'=>'1.2'
- # Is the same as:
- # filter.using :maven, 'version'=>'1.2'
- #
- # You can also pass a proc or method. It will be called with the file name
and content,
- # to return the mapped content.
- #
- # Without any mapping, all files are copied as is.
- def using(*args, &block)
- case args.first
- when Hash # Maven hash mapping
- using :maven, *args
- when Symbol # Mapping from a method
- raise ArgumentError, 'Expected mapper type followed by mapping hash'
unless args.size == 2 && Hash === args[1]
- @mapper, @mapping = *args
- when Regexp # Mapping using a regular expression
- raise ArgumentError, 'Expected regular expression followed by mapping
hash' unless args.size == 2 && Hash === args[1]
- @mapper, @mapping = *args
- else
- raise ArgumentError, 'Expected proc, method or a block' if args.size >
1 || (args.first && block)
- @mapping = args.first || block
- end
- self
- end
-
- # :call-seq:
- # run => boolean
- #
- # Runs the filter.
- def run
- raise 'No source directory specified, where am I going to find the files
to filter?' if sources.empty?
- sources.each { |source| raise "Source directory #{source} doesn't exist"
unless File.exist?(source.to_s) }
- raise 'No target directory specified, where am I going to copy the files
to?' if target.nil?
-
- copy_map = sources.flatten.map(&:to_s).inject({}) do |map, source|
- base = Pathname.new(source)
- files = FileList.recursive(source).
- map { |file| Pathname.new(file).relative_path_from(base).to_s }.
- select { |file| @include.empty? || @include.any? { |pattern|
File.fnmatch(pattern, file, File::FNM_PATHNAME) } }.
- reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern,
file, File::FNM_PATHNAME) } }
- files.each do |file|
- src, dest = File.expand_path(file, source), File.expand_path(file,
target.to_s)
- map[file] = src if !File.exist?(dest) || File.stat(src).mtime >
File.stat(dest).mtime
- end
- map
- end
-
- return false if copy_map.empty?
-
- verbose(Rake.application.options.trace || false) do
- mkpath target.to_s
- copy_map.each do |path, source|
- dest = File.expand_path(path, target.to_s)
- if File.directory?(source)
- mkpath dest
- else
- mkpath File.dirname(dest)
- case mapping
- when Proc, Method # Call on input, accept output.
- mapped = mapping.call(path, File.open(source, 'rb') { |file|
file.read })
- File.open(dest, 'wb') { |file| file.write mapped }
- when Hash # Map ${key} to value
- content = File.open(source, 'rb') { |file| file.read }
- if Symbol === @mapper
- mapped = send("[EMAIL PROTECTED]", content) { |key|
mapping[key] }
- else
- mapped = regexp_mapper(content) { |key| mapping[key] }
- end
- #gsub(/\$\{[^}]*\}/) { |str| mapping[str[2..-2]] || str }
- File.open(dest, 'wb') { |file| file.write mapped }
- when nil # No mapping.
- cp source, dest
- File.chmod(0664, dest)
- else
- fail "Filter can be a hash (key=>value), or a proc/method; I
don't understand #{mapping}"
- end
- end
- end
- touch target.to_s
- end
- true
- end
-
- # Returns the target directory.
- def to_s
- @target.to_s
- end
-
- private
-
- def maven_mapper(content)
- content.gsub(/\$\{.*?\}/) { |str| yield(str[2..-2]) || str }
- end
-
- def ant_mapper(content)
- content.gsub(/@.*?@/) { |str| yield(str[1..-2]) || str }
- end
-
- def ruby_mapper(content)
- content.gsub(/#\{.*?\}/) { |str| yield(str[2..-2]) || str }
- end
-
- def regexp_mapper(content)
- content.gsub(@mapper) { |str| yield(str.scan(@mapper).join) || str }
- end
-
- end
-
- # :call-seq:
- # filter(*source) => Filter
- #
- # Creates a filter that will copy files from the source directory(ies) into
the target directory.
- # You can extend the filter to modify files by mapping <tt>${key}</tt> into
values in each
- # of the copied files, and by including or excluding specific files.
- #
- # A filter is not a task, you must call the Filter#run method to execute it.
- #
- # For example, to copy all files from one directory to another:
- # filter('src/files').into('target/classes').run
- # To include only the text files, and replace each instance of
<tt>${build}</tt> with the current
- # date/time:
- #
filter('src/files').into('target/classes').include('*.txt').using('build'=>Time.now).run
- def filter(*sources)
- Filter.new.from(*sources)
- end
-
end
@@ -489,10 +308,10 @@
HighLine.use_color = PLATFORM !~ /win32/
module Kernel #:nodoc:
- def warn_with_color(message)
+ alias :warn_without_color :warn
+ def warn(message)
warn_without_color $terminal.color(message.to_s, :red)
end
- alias_method_chain :warn, :color
# :call-seq:
# warn_deprecated(message)
@@ -515,4 +334,3 @@
end
end
-
Modified: incubator/buildr/trunk/lib/core/compile.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/compile.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/compile.rb (original)
+++ incubator/buildr/trunk/lib/core/compile.rb Tue Mar 25 21:50:54 2008
@@ -83,8 +83,8 @@
def applies_to?(project, task)
paths = task.sources + [sources].flatten.map { |src|
Array(project.path_to(:source, task.usage, src.to_sym)) }
paths.flatten!
- ext_glob = source_ext.ergo { |ext| Array === ext ?
"{#{ext.join(',')}}" : ext }
- paths.any? { |path| !Dir["#{path}/**/*.#{ext_glob}"].empty? }
+ ext_glob = Array(source_ext).join(',')
+ paths.any? { |path| !Dir["#{path}/**/*.{#{ext_glob}}"].empty? }
end
# Implementations can use this method to specify various compiler
attributes.
@@ -138,7 +138,7 @@
self.class.dependencies
end
- private
+ protected
# Use this to complain about CompileTask options not supported by this
compiler.
#
@@ -154,8 +154,8 @@
# Expands a list of source directories/files into a list of files that
have the #source_ext extension.
def files_from_sources(sources)
- ext_glob = self.class.source_ext.ergo { |ext| Array === ext ?
"{#{ext.join(',')}}" : ext }
- sources.flatten.map { |source| File.directory?(source) ?
FileList["#{source}/**/*.#{ext_glob}"] : source }.
+ ext_glob = Array(self.class.source_ext).join(',')
+ sources.flatten.map { |source| File.directory?(source) ?
FileList["#{source}/**/*.{#{ext_glob}}"] : source }.
flatten.reject { |file| File.directory?(file) }.map { |file|
File.expand_path(file) }.uniq
end
@@ -165,20 +165,18 @@
# The default method maps all files in the source directories with
#source_ext into
# paths in the target directory with #target_ext (e.g.
'source/foo.java'=>'target/foo.class').
def compile_map(sources, target)
- source_ext = self.class.source_ext
target_ext = self.class.target_ext
- ext_glob = self.class.source_ext.ergo { |ext| Array === ext ?
"{#{ext.join(',')}}" : ext }
+ ext_glob = Array(self.class.source_ext).join(',')
sources.flatten.inject({}) do |map, source|
if File.directory?(source)
base = Pathname.new(source)
- FileList["#{source}/**/*.#{ext_glob}"].reject { |file|
File.directory?(file) }.
+ FileList["#{source}/**/*.{#{ext_glob}}"].reject { |file|
File.directory?(file) }.
each { |file| map[file] = File.join(target,
Pathname.new(file).relative_path_from(base).to_s.ext(target_ext)) }
else
map[source] = File.join(target,
File.basename(source).ext(target_ext))
end
map
end
-
end
end
Added: incubator/buildr/trunk/lib/core/filter.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/filter.rb?rev=641147&view=auto
==============================================================================
--- incubator/buildr/trunk/lib/core/filter.rb (added)
+++ incubator/buildr/trunk/lib/core/filter.rb Tue Mar 25 21:50:54 2008
@@ -0,0 +1,259 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
+module Buildr
+
+ # A filter knows how to copy files from one directory to another, applying
mappings to the
+ # contents of these files.
+ #
+ # You can specify the mapping using a Hash, and it will map ${key} fields
found in each source
+ # file into the appropriate value in the target file. For example:
+ #
+ # filter.using 'version'=>'1.2', 'build'=>Time.now
+ #
+ # will replace all occurrences of <tt>${version}</tt> with <tt>1.2</tt>, and
<tt>${build}</tt>
+ # with the current date/time.
+ #
+ # You can also specify the mapping by passing a proc or a method, that will
be called for
+ # each source file, with the file name and content, returning the modified
content.
+ #
+ # Without any mapping, the filter simply copies files from the source
directory into the target
+ # directory.
+ #
+ # A filter has one target directory, but you can specify any number of
source directories,
+ # either when creating the filter or calling #from. Include/exclude patterns
are specified
+ # relative to the source directories, so:
+ # filter.include '*.png'
+ # will only include PNG files from any of the source directories.
+ #
+ # See Buildr#filter.
+ class Filter
+
+ def initialize #:nodoc:
+ clear
+ end
+
+ # Returns the list of source directories (each being a file task).
+ attr_reader :sources
+
+ # :call-seq:
+ # clear => self
+ #
+ # Clear filter sources and include/exclude patterns
+ def clear
+ @include = []
+ @exclude = []
+ @sources = []
+ self
+ end
+
+ # :call-seq:
+ # from(*sources) => self
+ #
+ # Adds additional directories from which to copy resources.
+ #
+ # For example:
+ # filter.from('src').into('target').using('build'=>Time.now)
+ def from(*sources)
+ @sources |= sources.flatten.map { |dir| file(File.expand_path(dir.to_s))
}
+ self
+ end
+
+ # The target directory as a file task.
+ attr_reader :target
+
+ # :call-seq:
+ # into(dir) => self
+ #
+ # Sets the target directory into which files are copied and returns self.
+ #
+ # For example:
+ # filter.from('src').into('target').using('build'=>Time.now)
+ def into(dir)
+ @target = file(File.expand_path(dir.to_s)) { |task| run if target ==
task && !sources.empty? }
+ self
+ end
+
+ # :call-seq:
+ # include(*files) => self
+ #
+ # Specifies files to include and returns self. See FileList#include.
+ #
+ # By default all files are included. You can use this method to only
include specific
+ # files form the source directory.
+ def include(*files)
+ @include += files
+ self
+ end
+ alias :add :include
+
+ # :call-seq:
+ # exclude(*files) => self
+ #
+ # Specifies files to exclude and returns self. See FileList#exclude.
+ def exclude(*files)
+ @exclude += files
+ self
+ end
+
+ # The mapping. See #using.
+ attr_accessor :mapping
+
+ # The mapper to use. See #using.
+ attr_accessor :mapper
+
+ # :call-seq:
+ # using(mapping) => self
+ # using { |file_name, contents| ... } => self
+ #
+ # Specifies the mapping to use and returns self.
+ #
+ # The most typical mapping uses a Hash, and the default mapping uses the
Maven style, so
+ # <code>${key}</code> are mapped to the values. You can change that by
passing a different
+ # format as the first argument. Currently supports:
+ # * :ant -- Map <code>@key@</code>.
+ # * :maven -- Map <code>${key}</code> (default).
+ # * :ruby -- Map <code>#{key}</code>.
+ # * Regexp -- Maps the matched data (e.g. <code>/=(.*?)=/</code>
+ #
+ # For example:
+ # filter.using 'version'=>'1.2'
+ # Is the same as:
+ # filter.using :maven, 'version'=>'1.2'
+ #
+ # You can also pass a proc or method. It will be called with the file name
and content,
+ # to return the mapped content.
+ #
+ # Without any mapping, all files are copied as is.
+ def using(*args, &block)
+ case args.first
+ when Hash # Maven hash mapping
+ using :maven, *args
+ when Symbol # Mapping from a method
+ raise ArgumentError, 'Expected mapper type followed by mapping hash'
unless args.size == 2 && Hash === args[1]
+ @mapper, @mapping = *args
+ when Regexp # Mapping using a regular expression
+ raise ArgumentError, 'Expected regular expression followed by mapping
hash' unless args.size == 2 && Hash === args[1]
+ @mapper, @mapping = *args
+ else
+ raise ArgumentError, 'Expected proc, method or a block' if args.size >
1 || (args.first && block)
+ @mapping = args.first || block
+ end
+ self
+ end
+
+ # :call-seq:
+ # run => boolean
+ #
+ # Runs the filter.
+ def run
+ raise 'No source directory specified, where am I going to find the files
to filter?' if sources.empty?
+ sources.each { |source| raise "Source directory #{source} doesn't exist"
unless File.exist?(source.to_s) }
+ raise 'No target directory specified, where am I going to copy the files
to?' if target.nil?
+
+ copy_map = sources.flatten.map(&:to_s).inject({}) do |map, source|
+ base = Pathname.new(source)
+ files = FileList.recursive(source).
+ map { |file| Pathname.new(file).relative_path_from(base).to_s }.
+ select { |file| @include.empty? || @include.any? { |pattern|
File.fnmatch(pattern, file, File::FNM_PATHNAME) } }.
+ reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern,
file, File::FNM_PATHNAME) } }
+ files.each do |file|
+ src, dest = File.expand_path(file, source), File.expand_path(file,
target.to_s)
+ map[file] = src if !File.exist?(dest) || File.stat(src).mtime >
File.stat(dest).mtime
+ end
+ map
+ end
+
+ return false if copy_map.empty?
+
+ verbose(Rake.application.options.trace || false) do
+ mkpath target.to_s
+ copy_map.each do |path, source|
+ dest = File.expand_path(path, target.to_s)
+ if File.directory?(source)
+ mkpath dest
+ else
+ mkpath File.dirname(dest)
+ case mapping
+ when Proc, Method # Call on input, accept output.
+ mapped = mapping.call(path, File.open(source, 'rb') { |file|
file.read })
+ File.open(dest, 'wb') { |file| file.write mapped }
+ when Hash # Map ${key} to value
+ content = File.open(source, 'rb') { |file| file.read }
+ if Symbol === @mapper
+ mapped = send("[EMAIL PROTECTED]", content) { |key|
mapping[key] }
+ else
+ mapped = regexp_mapper(content) { |key| mapping[key] }
+ end
+ #gsub(/\$\{[^}]*\}/) { |str| mapping[str[2..-2]] || str }
+ File.open(dest, 'wb') { |file| file.write mapped }
+ when nil # No mapping.
+ cp source, dest
+ File.chmod(0664, dest)
+ else
+ fail "Filter can be a hash (key=>value), or a proc/method; I
don't understand #{mapping}"
+ end
+ end
+ end
+ touch target.to_s
+ end
+ true
+ end
+
+ # Returns the target directory.
+ def to_s
+ @target.to_s
+ end
+
+ private
+
+ def maven_mapper(content)
+ content.gsub(/\$\{.*?\}/) { |str| yield(str[2..-2]) || str }
+ end
+
+ def ant_mapper(content)
+ content.gsub(/@.*?@/) { |str| yield(str[1..-2]) || str }
+ end
+
+ def ruby_mapper(content)
+ content.gsub(/#\{.*?\}/) { |str| yield(str[2..-2]) || str }
+ end
+
+ def regexp_mapper(content)
+ content.gsub(@mapper) { |str| yield(str.scan(@mapper).join) || str }
+ end
+
+ end
+
+ # :call-seq:
+ # filter(*source) => Filter
+ #
+ # Creates a filter that will copy files from the source directory(ies) into
the target directory.
+ # You can extend the filter to modify files by mapping <tt>${key}</tt> into
values in each
+ # of the copied files, and by including or excluding specific files.
+ #
+ # A filter is not a task, you must call the Filter#run method to execute it.
+ #
+ # For example, to copy all files from one directory to another:
+ # filter('src/files').into('target/classes').run
+ # To include only the text files, and replace each instance of
<tt>${build}</tt> with the current
+ # date/time:
+ #
filter('src/files').into('target/classes').include('*.txt').using('build'=>Time.now).run
+ def filter(*sources)
+ Filter.new.from(*sources)
+ end
+
+end
Modified: incubator/buildr/trunk/lib/core/project.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/project.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/project.rb (original)
+++ incubator/buildr/trunk/lib/core/project.rb Tue Mar 25 21:50:54 2008
@@ -18,30 +18,6 @@
module Buildr
- # *Deprecated*
- module InheritedAttributes #:nodoc:
-
- def self.included(base)
- base.extend(self)
- warn_deprecated 'InheritedAttributes are deprecated'
- end
-
- def inherited_attr(symbol, default = nil, &block)
- block ||= proc { default }
- attr_accessor symbol
- define_method "#{symbol}_with_inheritence" do
- value = send("#{symbol}_without_inheritence")
- if value.nil?
- value = parent ? parent.send(symbol) : self.instance_eval(&block)
- send "#{symbol}=", value
- end
- value
- end
- alias_method_chain symbol, :inheritence
- end
- end
-
-
# Symbolic mapping for directory layout. Used for both the default and
custom layouts.
#
# For example, the default layout maps [:source, :main, :java] to
'src/main/java', and
Modified: incubator/buildr/trunk/lib/core/transports.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/transports.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/transports.rb (original)
+++ incubator/buildr/trunk/lib/core/transports.rb Tue Mar 25 21:50:54 2008
@@ -23,10 +23,8 @@
require 'uri/sftp'
require 'digest/md5'
require 'digest/sha1'
-require 'facets/progressbar'
-require 'highline'
+require 'progressbar'
require 'tempfile'
-require 'uri/sftp'
# Monkeypatching: SFTP never defines the mkdir method on its session or the
underlying
@@ -337,7 +335,7 @@
http.use_ssl = true if self.instance_of? URI::HTTPS
puts "Requesting #{self}" if Rake.application.options.trace
- request = Net::HTTP::Get.new(path.blank? ? '/' : path, headers)
+ request = Net::HTTP::Get.new(path.empty? ? '/' : path, headers)
request.basic_auth self.user, self.password if self.user
http.request request do |response|
case response
@@ -472,7 +470,7 @@
# See URI::Generic#read
def read(options = nil, &block)
options ||= {}
- raise ArgumentError, 'Either you\'re attempting to read a file from
another host (which we don\'t support), or you used two slashes by mistake,
where you should have file:///<path>.' unless host.to_s.blank?
+ raise ArgumentError, 'Either you\'re attempting to read a file from
another host (which we don\'t support), or you used two slashes by mistake,
where you should have file:///<path>.' if host
path = real_path
# TODO: complain about clunky URLs
@@ -499,7 +497,7 @@
protected
def write_internal(options, &block) #:nodoc:
- raise ArgumentError, 'Either you\'re attempting to write a file to
another host (which we don\'t support), or you used two slashes by mistake,
where you should have file:///<path>.' unless host.to_s.blank?
+ raise ArgumentError, 'Either you\'re attempting to write a file to
another host (which we don\'t support), or you used two slashes by mistake,
where you should have file:///<path>.' if host
temp = nil
Tempfile.open File.basename(path) do |temp|
temp.binmode
Modified: incubator/buildr/trunk/lib/java/artifact.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/artifact.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/artifact.rb (original)
+++ incubator/buildr/trunk/lib/java/artifact.rb Tue Mar 25 21:50:54 2008
@@ -70,7 +70,7 @@
# :version=>'1.2' }
def to_spec_hash
base = { :group=>group, :id=>id, :type=>type, :version=>version }
- classifier.to_s.blank? ? base : base.merge(:classifier=>classifier)
+ classifier ? base.merge(:classifier=>classifier) : base
end
alias_method :to_hash, :to_spec_hash
@@ -82,7 +82,7 @@
# or
# <group>:<artifact>:<type>:<classifier><:version>
def to_spec
- classifier.to_s.blank? ? "#{group}:#{id}:#{type}:#{version}" :
"#{group}:#{id}:#{type}:#{classifier}:#{version}"
+ classifier ? "#{group}:#{id}:#{type}:#{classifier}:#{version}" :
"#{group}:#{id}:#{type}:#{version}"
end
# :call-seq:
@@ -146,7 +146,7 @@
# Where do we release to?
upload_to ||= Buildr.repositories.release_to
upload_to = { :url=>upload_to } unless Hash === upload_to
- raise ArgumentError, 'Don\'t know where to upload, perhaps you forgot to
set repositories.release_to' if upload_to[:url].to_s.blank?
+ raise ArgumentError, 'Don\'t know where to upload, perhaps you forgot to
set repositories.release_to' unless upload_to[:url]
invoke # Make sure we exist.
# Upload POM ahead of package, so we don't fail and find POM-less
package (the horror!)
@@ -246,13 +246,13 @@
rake_check_options spec, :id, :group, :type, :classifier, :version
# Sanitize the hash and check it's valid.
spec = ARTIFACT_ATTRIBUTES.inject({}) { |h, k| h[k] = spec[k].to_s
if spec[k] ; h }
- fail "Missing group identifier for #{spec.inspect}" if
spec[:group].to_s.blank?
- fail "Missing artifact identifier for #{spec.inspect}" if
spec[:id].to_s.blank?
- fail "Missing version for #{spec.inspect}" if
spec[:version].to_s.blank?
- spec[:type] = spec[:type].to_s.blank? ? DEFAULT_TYPE :
spec[:type].to_sym
+ fail "Missing group identifier for #{spec.inspect}" unless
spec[:group]
+ fail "Missing artifact identifier for #{spec.inspect}" unless
spec[:id]
+ fail "Missing version for #{spec.inspect}" unless spec[:version]
+ spec[:type] = (spec[:type] || DEFAULT_TYPE).to_sym
spec
elsif String === spec
- group, id, type, version, *rest = spec.split(':')
+ group, id, type, version, *rest = spec.split(':').map { |part|
part.empty? ? nil : part }
unless rest.empty?
# Optional classifier comes before version.
classifier, version = version, rest.shift
@@ -271,8 +271,8 @@
# a string, hash or any object that responds to to_spec.
def to_spec(hash)
hash = to_hash(hash) unless Hash === hash
- version = ":#{hash[:version]}" unless hash[:version].to_s.blank?
- classifier = ":#{hash[:classifier]}" unless
hash[:classifier].to_s.blank?
+ version = ":#{hash[:version]}" if hash[:version]
+ classifier = ":#{hash[:classifier]}" if hash[:classifier]
"#{hash[:group]}:#{hash[:id]}:#{hash[:type] ||
DEFAULT_TYPE}#{classifier}#{version}"
end
@@ -281,8 +281,8 @@
#
# Convert a hash spec to a file name.
def hash_to_file_name(hash)
- version = "-#{hash[:version]}" unless hash[:version].to_s.blank?
- classifier = "-#{hash[:classifier]}" unless
hash[:classifier].to_s.blank?
+ version = "-#{hash[:version]}" if hash[:version]
+ classifier = "-#{hash[:classifier]}" if hash[:classifier]
"#{hash[:id]}#{version}#{classifier}.#{hash[:type] || DEFAULT_TYPE}"
end
Modified: incubator/buildr/trunk/lib/java/packaging.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/packaging.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/packaging.rb (original)
+++ incubator/buildr/trunk/lib/java/packaging.rb Tue Mar 25 21:50:54 2008
@@ -30,7 +30,10 @@
module WithManifest #:nodoc:
def self.included(base)
- base.send :alias_method_chain, :initialize, :manifest
+ base.class_eval do
+ alias :initialize_without_manifest :initialize
+ alias :initialize :initialize_with_manifest
+ end
end
MANIFEST_HEADER = ['Manifest-Version: 1.0', 'Created-By: Buildr']
Modified: incubator/buildr/trunk/lib/java/pom.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/pom.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/pom.rb (original)
+++ incubator/buildr/trunk/lib/java/pom.rb Tue Mar 25 21:50:54 2008
@@ -103,7 +103,7 @@
[Artifact.to_spec(spec)] + transitive_deps
end
- }.flatten.compact.uniq_by{|spec| art = spec.split(':');
"#{art[0]}:#{art[1]}"}
+ }.flatten.compact #.uniq_by{|spec| art = spec.split(':');
"#{art[0]}:#{art[1]}"}
@depends_for_scopes[scopes] = depends
end
Modified: incubator/buildr/trunk/lib/tasks/zip.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/tasks/zip.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/tasks/zip.rb (original)
+++ incubator/buildr/trunk/lib/tasks/zip.rb Tue Mar 25 21:50:54 2008
@@ -32,7 +32,7 @@
def initialize(root, path)
@root = root
- @path = path.to_s.blank? ? path : "#{path}/"
+ @path = path.empty? ? path : "#{path}/"
@includes = FileList[]
@excludes = []
# Expand source files added to this path.
@@ -120,7 +120,7 @@
# Returns a Path relative to this one.
def path(path)
- return self if path.to_s.blank?
+ return self if path.nil?
return root.path(path[1..-1]) if path[0] == ?/
root.path("[EMAIL PROTECTED]")
end
@@ -245,7 +245,7 @@
mkpath File.dirname(name), :verbose=>false
begin
@paths.each do |name, object|
- @file_map[name] = nil unless name.to_s.blank?
+ @file_map[name] = nil unless name.empty?
object.add_files(@file_map)
end
create_from @file_map
@@ -346,7 +346,7 @@
# path('foo').path('bar') == path('foo/bar')
# path('foo').root == root
def path(name)
- return @paths[''] if name.to_s.blank?
+ return @paths[''] if name.nil?
normalized = name.split('/').inject([]) do |path, part|
case part
when '.', nil, ''
Modified: incubator/buildr/trunk/spec/addon_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/addon_spec.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/addon_spec.rb (original)
+++ incubator/buildr/trunk/spec/addon_spec.rb Tue Mar 25 21:50:54 2008
@@ -16,7 +16,7 @@
require File.join(File.dirname(__FILE__), 'spec_helpers')
-
+=begin
describe Buildr, 'addon' do
before do
@@ -173,3 +173,4 @@
Gem.loaded_specs.replace @loaded_specs
end
end
+=end
Modified: incubator/buildr/trunk/spec/artifact_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/artifact_spec.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/artifact_spec.rb (original)
+++ incubator/buildr/trunk/spec/artifact_spec.rb Tue Mar 25 21:50:54 2008
@@ -344,6 +344,7 @@
end
it 'should reject partial string specifier' do
+ 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
Modified: incubator/buildr/trunk/spec/project_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/project_spec.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/project_spec.rb (original)
+++ incubator/buildr/trunk/spec/project_spec.rb Tue Mar 25 21:50:54 2008
@@ -701,57 +701,6 @@
end
-describe InheritedAttributes do
- before do
- class TestAttributes
- include InheritedAttributes
- inherited_attr :foo
- inherited_attr :bar do 'barring' end
- attr_accessor :parent
- end
- @parent = TestAttributes.new
- @child = TestAttributes.new
- @child.parent = @parent
- end
-
- it 'should have getter and setter methods' do
- @parent.foo = 'foo'
- @parent.bar = 'bar'
- @parent.foo.should eql('foo')
- @parent.bar.should eql('bar')
- end
-
- it 'should take default value from block' do
- @parent.foo.should be_nil
- @parent.bar.should eql('barring')
- end
-
- it 'should take default value from parent' do
- @child.foo.should be_nil
- @parent.foo = 'foo'
- @child.foo.should eql('foo')
- @child.foo.should be(@parent.foo)
- end
-
- it 'should cache default value from parent' do
- @parent.foo = 'foo'
- @child.foo.should eql('foo')
- @parent.foo = 'bar'
- @child.foo.should eql('foo')
- end
-
- it 'should set value in child separately from parent' do
- @child.bar = 'barred'
- @child.bar.should eql('barred')
- @parent.bar.should eql('barring')
- end
-
- after do
- Object.send :remove_const, TestAttributes.name
- end
-end
-
-
describe Rake::Task, 'buildr:initialize' do
it 'should be ready to run as the first task' do
Rake.application.top_level_tasks.first.should eql('buildr:initialize')
Modified: incubator/buildr/trunk/spec/spec_helpers.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/spec_helpers.rb?rev=641147&r1=641146&r2=641147&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/spec_helpers.rb (original)
+++ incubator/buildr/trunk/spec/spec_helpers.rb Tue Mar 25 21:50:54 2008
@@ -39,10 +39,10 @@
$warning << message
end
- def warn_deprecated_with_capture(message)
+ alias :warn_deprecated_without_capture :warn_deprecated
+ def warn_deprecated(message)
verbose(true) { warn_deprecated_without_capture message }
end
- alias_method_chain :warn_deprecated, :capture
end
class WarningMatcher
@@ -75,12 +75,12 @@
class ::Rake::Task
- def execute_with_a_record(args)
+ alias :execute_without_a_record :execute
+ def execute(args)
$executed ||= []
$executed << name
execute_without_a_record args
end
- alias_method_chain :execute, :a_record
end
class InvokeMatcher