buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject svn commit: r609118 [1/2] - in /incubator/buildr/trunk: ./ lib/ lib/core/ lib/java/ spec/
Date Sat, 05 Jan 2008 10:07:08 GMT
Author: assaf
Date: Sat Jan  5 02:06:53 2008
New Revision: 609118

URL: http://svn.apache.org/viewvc?rev=609118&view=rev
Log:
Simplified the packaging API, and lets the compiler pick the default package type, if not, use :zip

Added:
    incubator/buildr/trunk/lib/core/package.rb
    incubator/buildr/trunk/spec/spec_helpers.rb
Modified:
    incubator/buildr/trunk/CHANGELOG
    incubator/buildr/trunk/lib/core.rb
    incubator/buildr/trunk/lib/core/build.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/test.rb
    incubator/buildr/trunk/lib/java/compilers.rb
    incubator/buildr/trunk/lib/java/packaging.rb
    incubator/buildr/trunk/lib/java/test_frameworks.rb
    incubator/buildr/trunk/spec/archive_spec.rb
    incubator/buildr/trunk/spec/artifact_spec.rb
    incubator/buildr/trunk/spec/build_spec.rb
    incubator/buildr/trunk/spec/checks_spec.rb
    incubator/buildr/trunk/spec/common_spec.rb
    incubator/buildr/trunk/spec/compile_spec.rb
    incubator/buildr/trunk/spec/packaging_spec.rb
    incubator/buildr/trunk/spec/project_spec.rb
    incubator/buildr/trunk/spec/sandbox.rb
    incubator/buildr/trunk/spec/test_spec.rb
    incubator/buildr/trunk/spec/transport_spec.rb

Modified: incubator/buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Sat Jan  5 02:06:53 2008
@@ -10,6 +10,8 @@
 * Changed: Test extension and TestTask are now separate from the Java module.  JUnit and TestNG are Java specific extensions picked using test.with(:name).
 * Changed: For compile and test, use dependencies instead of classpath (with works are before).
 * Changed: Test framework componentized along the same lines as the compilers.
+* Changed: The way packaging is handled: package_as_[type] is now called once for a given package with the exact file name.  If packaging requires a change to the specifiction (e.g. a different file type than the package type), add a package_as_[type]_spec method.
+* Changed: The default packaging type is inferred from the compiler, and without a compiler, defaults to :zip.
 * Removed: Prepare tasks removed.
 * Removed: All deprecated features since 1.1.  If you've seen warnings before, except the build to break.
 * Fixed: Artifact.pom resolves artifact without classifier, i.e org.testng:testng:jar:jdk15:5.1 uses org.testng:testng:pom:5.1 (Tommy).

Modified: incubator/buildr/trunk/lib/core.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core.rb (original)
+++ incubator/buildr/trunk/lib/core.rb Sat Jan  5 02:06:53 2008
@@ -3,8 +3,10 @@
 require 'core/environment'
 require 'core/help'
 require 'core/build'
+require 'core/package'
 require 'core/compile'
 require 'core/test'
+require 'core/checks'
 require 'core/generate'
 
 class Buildr::Project
@@ -14,5 +16,6 @@
   include Buildr::Build
   include Buildr::Compile
   include Buildr::Test
+  include Buildr::Package
   include Buildr::Checks
 end

Modified: incubator/buildr/trunk/lib/core/build.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/build.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/build.rb (original)
+++ incubator/buildr/trunk/lib/core/build.rb Sat Jan  5 02:06:53 2008
@@ -23,8 +23,6 @@
 
   module Build
 
-    BUILD_TASKS = [ :build, :clean, :package, :install, :uninstall, :upload ]
-
     include Extension
 
     first_time do
@@ -32,21 +30,14 @@
       Project.local_task('build') { |name| "Building #{name}" }
       desc 'Clean files generated during a build'
       Project.local_task('clean') { |name| "Cleaning #{name}" }
-      desc 'Create packages'
-      Project.local_task('package'=>'build') { |name| "Packaging #{name}" }
-      desc 'Install packages created by the project'
-      Project.local_task('install'=>'package') { |name| "Installing packages from #{name}" }
-      desc 'Remove previously installed packages'
-      Project.local_task('uninstall') { |name| "Uninstalling packages from #{name}" }
-      desc 'Upload packages created by the project'
-      Project.local_task('upload'=>'package') { |name| "Deploying packages from #{name}" }
 
       desc 'The default task it build'
       task 'default'=>'build'
     end
 
     before_define do |project|
-      BUILD_TASKS.each { |name| project.recursive_task name }
+      project.recursive_task 'build'
+      project.recursive_task 'clean'
       project.clean do
         verbose(true) do
           rm_rf project.path_to(:target)

Modified: incubator/buildr/trunk/lib/core/common.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/common.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/common.rb (original)
+++ incubator/buildr/trunk/lib/core/common.rb Sat Jan  5 02:06:53 2008
@@ -244,7 +244,7 @@
     # 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)) }
+      @sources |= sources.flatten.map { |dir| file(dir.to_s) }
       self
     end
 
@@ -259,7 +259,7 @@
     # 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? }
+      @target = file(dir.to_s) { |task| run if target == task && !sources.empty? }
       self
     end
 

Modified: incubator/buildr/trunk/lib/core/compile.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/compile.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/compile.rb (original)
+++ incubator/buildr/trunk/lib/core/compile.rb Sat Jan  5 02:06:53 2008
@@ -1,14 +1,22 @@
 require "core/common"
 
 module Buildr
+
+  # The underlying compiler used by CompileTask.
+  # To add a new compiler, extend Compiler::Base and add your compiler using:
+  #   Buildr::Compiler.add MyCompiler
   module Compiler
 
     class << self
 
+      # Returns true if the specified compiler exists.
+      def has?(name)
+        @compilers.has_key?(name.to_sym)
+      end
+
       # Select a compiler by its name.
       def select(name)
-        raise ArgumentError, "No #{name} compiler available. Did you install it?" unless @compilers.has_key?(name.to_sym)
-        @compilers[name.to_sym]
+        @compilers[name.to_sym] or raise ArgumentError, "No #{name} compiler available. Did you install it?"
       end
 
       # Identify which compiler applies based on one of two arguments:
@@ -20,18 +28,23 @@
       end
 
       # Adds a compiler to the list of supported compiler.
+      #   
+      # For example:
+      #   Buildr::Compiler.add Buildr::Javac
       def add(compiler)
-        @compilers ||= {}
         compiler = compiler.new if Class === compiler
         @compilers[compiler.name.to_sym] = compiler
       end
 
-      def compilers #:nodoc:
+      # Returns a list of available compilers.
+      def compilers
         @compilers.values.clone
       end
 
     end
 
+    @compilers = {}
+
 
     # Base class for all compilers, with common functionality.  Extend and over-ride as you see fit
     # (see Javac as an example).
@@ -57,6 +70,8 @@
       attr_reader :target_path
       # Extension for target files (e.g. '.class').
       attr_reader :target_ext
+      # The default packaging type (e.g. :jar).
+      attr_reader :packaging
 
       # Used by Compiler.identify to determine if this compiler applies to the current project.
       # The default implementation looks for either the supplied source directories, or the
@@ -109,7 +124,7 @@
         parent = Project.task_in_parent_project(task.name)
         if parent.respond_to?(:options)
           missing = supported.flatten - task.options.to_hash.keys
-          task.options.merge( missing.inject({}) { |hash, key| hash.update(key=>parent.options[key]) } )
+          missing.each { |option| task.options[option] = parent.options[option] }
         end
       end
 
@@ -159,7 +174,7 @@
     def initialize(*args) #:nodoc:
       super
       parent = Project.task_in_parent_project(name)
-      @options = OpenObject.new#(parent.respond_to?(:options) && parent.options)
+      @options = OpenObject.new
       @sources = []
       @dependencies = []
 
@@ -238,8 +253,7 @@
     #   compile(src_dir).into(target_dir).with(artifacts)
     # Both compile.invoke and file(target_dir).invoke will compile the source files.
     def into(path)
-      path = File.expand_path(path.to_s)
-      @target = file(path).enhance([self]) unless @target && @target.to_s == path
+      @target = file(path.to_s).enhance([self]) unless @target.to_s == path.to_s
       self
     end
 
@@ -257,7 +271,7 @@
     #   compile.using(:scala)
     def using(*args)
       args.pop.each { |key, value| options.send "#{key}=", value } if Hash === args.last
-      select args.pop until args.empty?
+      self.compiler = args.pop until args.empty?
       self
     end
 
@@ -265,10 +279,7 @@
     # based on existing source directories (e.g. src/main/java), or by requesting
     # a specific compiler (see #using).
     def compiler
-      unless @compiler
-        compiler = Compiler.identify(:sources=>sources) unless sources.empty?
-        select(compiler) if compiler
-      end
+      self.compiler = Compiler.identify(:sources=>sources) unless sources.empty? || @compiler
       @compiler && @compiler.name
     end
 
@@ -277,6 +288,11 @@
       compiler && @compiler.language
     end
 
+    # Returns the default packaging type for this compiler, if known.
+    def packaging
+      compiler && @compiler.packaging
+    end
+
     def timestamp #:nodoc:
       # If we compiled successfully, then the target directory reflects that.
       # If we didn't, see needed?
@@ -286,7 +302,8 @@
   protected
 
     # Selects which compiler to use.
-    def select(compiler) #:nodoc:
+    def compiler=(compiler) #:nodoc:
+      return self unless compiler
       compiler = Compiler.select(compiler) unless Compiler::Base === compiler
       unless @compiler == compiler
         raise "#{@compiler} compiler already selected for this project" if @compiler
@@ -298,8 +315,7 @@
 
     def associate(source, target) #:nodoc:
       @associate = { :source=>source, :target=>target }
-      compiler = Compiler.identify(:source=>source)
-      select(compiler) if compiler
+      self.compiler = Compiler.identify(:source=>source)
     end
 
   private
@@ -314,7 +330,6 @@
       return true if compile_map.any? { |source, target| !File.exist?(target) || File.stat(source).mtime > File.stat(target).mtime }
       oldest = compile_map.map { |source, target| File.stat(target).mtime }.min
       return dependencies.any? { |path| application[path].timestamp > oldest }
-      return true
     end
 
     def invoke_prerequisites(args, chain) #:nodoc:
@@ -419,6 +434,7 @@
     end
 
     after_define do |project|
+      file(project.resources.target.to_s => project.resources) if project.resources.target
       if project.compile.target
         # This comes last because the target path is set inside the project definition.
         project.build project.compile.target

Added: incubator/buildr/trunk/lib/core/package.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/package.rb?rev=609118&view=auto
==============================================================================
--- incubator/buildr/trunk/lib/core/package.rb (added)
+++ incubator/buildr/trunk/lib/core/package.rb Sat Jan  5 02:06:53 2008
@@ -0,0 +1,213 @@
+require 'core/project'
+require 'core/compile'
+require 'java/artifact'
+
+module Buildr
+  # Methods added to Project to support packaging and tasks for packaging,
+  # installing and uploading packages.
+  module Package
+
+    include Extension
+
+    first_time do
+      desc 'Create packages'
+      Project.local_task('package'=>'build') { |name| "Packaging #{name}" }
+      desc 'Install packages created by the project'
+      Project.local_task('install'=>'package') { |name| "Installing packages from #{name}" }
+      desc 'Remove previously installed packages'
+      Project.local_task('uninstall') { |name| "Uninstalling packages from #{name}" }
+      desc 'Upload packages created by the project'
+      Project.local_task('upload'=>'package') { |name| "Deploying packages from #{name}" }
+      # Anything that comes after local packaging (install, deploy) executes the integration tests,
+      # which do not conflict with integration invoking the project's own packaging (package=>
+      # integration=>foo:package is not circular, just confusing to debug.)
+      task 'package' do
+        task('integration').invoke if Buildr.options.test && Rake.application.original_dir == Dir.pwd
+      end
+    end
+
+    before_define do |project|
+      [ :package, :install, :uninstall, :upload ].each { |name| project.recursive_task name }
+      # Need to run build before package, since package is often used as a dependency by tasks that
+      # expect build to happen.
+      project.task('package'=>project.task('build'))
+      project.group ||= project.parent && project.parent.group || project.name
+      project.version ||= project.parent && project.parent.version
+    end
+
+    # The project's identifier. Same as the project name, with colons replaced by dashes.
+    # The ID for project foo:bar is foo-bar.
+    def id
+      name.gsub(':', '-')
+    end
+
+    # Group used for packaging. Inherited from parent project. Defaults to the top-level project name.
+    attr_accessor :group
+
+    # Version used for packaging. Inherited from parent project.
+    attr_accessor :version
+
+    # :call-seq:
+    #   package(type, spec?) => task
+    #
+    # Defines and returns a package created by this project.
+    #
+    # The first argument declares the package type. For example, :jar to create a JAR file.
+    # The package is an artifact that takes its artifact specification from the project.
+    # You can override the artifact specification by passing various options in the second
+    # argument, for example:
+    #   package(:zip, :classifier=>'sources')
+    #
+    # Packages that are ZIP files provides various ways to include additional files, directories,
+    # and even merge ZIPs together. Have a look at ZipTask for more information. In case you're
+    # wondering, JAR and WAR packages are ZIP files.
+    #
+    # You can also enhance a JAR package using the ZipTask#with method that accepts the following options:
+    # * :manifest -- Specifies how to create the MANIFEST.MF. By default, uses the project's
+    #   #manifest property.
+    # * :meta_inf -- Specifies files to be included in the META-INF directory. By default,
+    #   uses the project's #meta-inf property.
+    #
+    # The WAR package supports the same options and adds a few more:
+    # * :classes -- Directories of class files to include in WEB-INF/classes. Includes the compile
+    #   target directory by default.
+    # * :libs -- Artifacts and files to include in WEB-INF/libs. Includes the compile classpath
+    #   dependencies by default.
+    #
+    # For example:
+    #   define 'project' do
+    #     define 'beans' do
+    #       package :jar
+    #     end
+    #     define 'webapp' do
+    #       compile.with project('beans')
+    #       package(:war).with :libs=>MYSQL_JDBC
+    #     end
+    #     package(:zip, :classifier=>'sources').include path_to('.')
+    #  end
+    #
+    # Two other packaging types are:
+    # * package :sources -- Creates a ZIP file with the source code and classifier 'sources', for use by IDEs.
+    # * package :javadoc -- Creates a ZIP file with the Javadocs and classifier 'javadoc'. You can use the
+    #   javadoc method to further customize it.
+    #
+    # A package is also an artifact. The following tasks operate on packages created by the project:
+    #   buildr upload     # Upload packages created by the project
+    #   buildr install    # Install packages created by the project
+    #   buildr package    # Create packages
+    #   buildr uninstall  # Remove previously installed packages
+    #
+    # If you want to add additional packaging types, implement a method with the name package_as_[type]
+    # that accepts a file name and returns an appropriate Rake task.  For example:
+    #   def package_as_zip(file_name) #:nodoc:
+    #     ZipTask.define_task(file_name)
+    #   end
+    #
+    # The file name is determined from the specification passed to the package method, however, some
+    # packagers need to override this.  For example, package(:sources) produces a file with the extension
+    # 'zip' and the classifier 'sources'.  If you need to overwrite the default implementation, you should
+    # also include a method named package_as_[type]_respec.  For example:
+    #   def package_as_sources_spec(spec) #:nodoc:
+    #     { :type=>:zip, :classifier=>'sources' }.merge(spec)
+    #   end
+    def package(type = nil, spec = nil)
+      spec = spec.nil? ? {} : spec.dup
+      type ||= compile.packaging || :zip
+      rake_check_options spec, *ActsAsArtifact::ARTIFACT_ATTRIBUTES
+      spec[:id] ||= self.id
+      spec[:group] ||= self.group
+      spec[:version] ||= self.version
+      spec[:type] ||= type
+
+      packager = method("package_as_#{type}") rescue
+        fail("Don't know how to create a package of type #{type}")
+      if packager.arity == 1
+        spec = send("package_as_#{type}_spec", spec) if respond_to?("package_as_#{type}_spec")
+        file_name = path_to(:target, Artifact.hash_to_file_name(spec))
+        package = Rake::Task[file_name] rescue packager.call(file_name)
+      else
+        warn_deprecated "We changed the way package_as methods are implemented.  See the package method documentation for more details."
+        file_name = path_to(:target, Artifact.hash_to_file_name(spec))
+        package = packager.call(file_name, spec)
+      end
+      unless packages.include?(package)
+        # Make it an artifact using the specifications, and tell it how to create a POM.
+        package.extend ActsAsArtifact
+        package.send :apply_spec, spec.only(*Artifact::ARTIFACT_ATTRIBUTES)
+        # Another task to create the POM file.
+        pom = package.pom
+        pom.enhance do
+          mkpath File.dirname(pom.name), :verbose=>false
+          File.open(pom.name, 'w') { |file| file.write pom.pom_xml }
+        end
+
+        # We already run build before package, but we also need to do so if the package itself is
+        # used as a dependency, before we get to run the package task.
+        task 'package'=>package
+        package.enhance [task('build')]
+
+        # Install the artifact along with its POM. Since the artifact (package task) is created
+        # in the target directory, we need to copy it into the local repository. However, the
+        # POM artifact (created by calling artifact on its spec) is already mapped to its right
+        # place in the local repository, so we only need to invoke it.
+        installed = file(Buildr.repositories.locate(package)=>package) { |task|
+          verbose(Rake.application.options.trace || false) do
+            mkpath File.dirname(task.name), :verbose=>false
+            cp package.name, task.name
+          end
+          puts "Installed #{task.name}" if verbose
+        }
+        task 'install'=>[installed, pom]
+        task 'uninstall' do |task|
+          verbose(Rake.application.options.trace || false) do
+            [ installed, pom ].map(&:to_s).each { |file| rm file if File.exist?(file) } 
+          end
+        end
+        task('upload') { package.pom.invoke ; package.pom.upload ; package.upload }
+
+        # Add the package to the list of packages created by this project, and
+        # register it as an artifact. The later is required so if we look up the spec
+        # we find the package in the project's target directory, instead of finding it
+        # in the local repository and attempting to install it.
+        packages << package
+        Artifact.register package, pom
+      end
+      package
+    end
+
+    # :call-seq:
+    #   packages => tasks
+    #
+    # Returns all packages created by this project. A project may create any number of packages.
+    #
+    # This method is used whenever you pass a project to Buildr#artifact or any other method
+    # that accepts artifact specifications and projects. You can use it to list all packages
+    # created by the project. If you want to return a specific package, it is often more
+    # convenient to call #package with the type.
+    def packages
+      @packages ||= []
+    end
+
+  protected
+
+    def package_as_zip(file_name) #:nodoc:
+      ZipTask.define_task(file_name)
+    end
+
+    def package_as_tar(file_name) #:nodoc:
+      TarTask.define_task(file_name)
+    end
+    alias :package_as_tgz :package_as_tar
+
+    def package_as_sources_spec(spec) #:nodoc:
+      spec.merge(:type=>:zip, :classifier=>'sources')
+    end
+
+    def package_as_sources(file_name) #:nodoc:
+      ZipTask.define_task(file_name).tap do |zip|
+        zip.include :from=>compile.sources
+      end
+    end
+
+  end
+end

Modified: incubator/buildr/trunk/lib/core/project.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/project.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/project.rb (original)
+++ incubator/buildr/trunk/lib/core/project.rb Sat Jan  5 02:06:53 2008
@@ -424,7 +424,7 @@
         if parent
           # For sub-project, a good default is a directory in the parent's base_dir,
           # using the same name as the project.
-          @base_dir = File.join(parent.base_dir, name.split(':').last)
+          @base_dir = File.expand_path(name.split(':').last, parent.base_dir)
         else
           # For top-level project, a good default is the directory where we found the Buildfile.
           @base_dir = Dir.pwd

Modified: incubator/buildr/trunk/lib/core/test.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/test.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/test.rb (original)
+++ incubator/buildr/trunk/lib/core/test.rb Sat Jan  5 02:06:53 2008
@@ -5,30 +5,48 @@
 
 module Buildr
 
+  # The underlying test framework used by TestTask.
+  # To add a new test framework, extend TestFramework::Base and add your framework using:
+  #   Buildr::TestFramework.add MyFramework
   class TestFramework
 
     class << self
+
+      # Returns true if the specified test framework exists.
       def has?(name)
-        frameworks.has_key?(name)
+        @frameworks.has_key?(name.to_sym)
       end
 
+      # Select a test framework by its name.
       def select(name)
-        raise ArgumentError, "No #{name} framework available. Did you install it?" unless frameworks.include?(name.to_sym)
-        frameworks[name.to_sym]
+        @frameworks[name.to_sym] or raise ArgumentError, "No #{name} framework available. Did you install it?"
+      end
+
+      # Identify which compiler applies for this project.
+      def identify_from(project)
+        @frameworks.values.detect { |framework| compiler.supports?(project) }
       end
 
       # Adds a test framework to the list of supported frameworks.
+      #   
+      # For example:
+      #   Buildr::TestFramework.add Buildr::JUnit
       def add(framework)
         framework = framework.new if Class === framework
-        frameworks[framework.name.to_sym] = framework
+        @frameworks[framework.name.to_sym] = framework
       end
 
-      def frameworks #:nodoc:
-        @frameworks ||= {}
+      # Returns a list of available test frameworks.
+      def frameworks
+        @frameworks.values.clone
       end
 
     end
 
+    @frameworks = {}
+
+    # Base class for all test frameworks, with common functionality.  Extend and over-ride as you see fit
+    # (see JUnit as an example).
     class Base
 
       def initialize(args = {})
@@ -46,6 +64,10 @@
         Dir[*Array(patterns).map { |pattern| "#{path}/**/#{pattern}" }]
       end
 
+      def supports?(project)
+        false
+      end
+
     end
   
   end
@@ -307,6 +329,7 @@
     #
     # Returns the test framework, e.g. :junit, :testng.
     def framework
+      @framework ||= TestFramework.identify_from(@project)
       @framework && @framework.name
     end
 
@@ -435,12 +458,6 @@
         end
       end
 
-      # Anything that comes after local packaging (install, deploy) executes the integration tests,
-      # which do not conflict with integration invoking the project's own packaging (package=>
-      # integration=>foo:package is not circular, just confusing to debug.)
-      task 'package' do
-        task('integration').invoke if Buildr.options.test && Rake.application.original_dir == Dir.pwd
-      end
     end
     
     before_define do |project|

Modified: incubator/buildr/trunk/lib/java/compilers.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/compilers.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/compilers.rb (original)
+++ incubator/buildr/trunk/lib/java/compilers.rb Sat Jan  5 02:06:53 2008
@@ -26,7 +26,7 @@
       OPTIONS = [:warnings, :debug, :deprecation, :source, :target, :lint, :other]
 
       def initialize #:nodoc:
-        super :language=>:java, :target_path=>'classes', :target_ext=>'.class'
+        super :language=>:java, :target_path=>'classes', :target_ext=>'.class', :packaging=>:jar
       end
 
       def configure(task, source, target) #:nodoc:
@@ -91,7 +91,8 @@
         @files = FileList[]
         enhance do |task|
           rm_rf target.to_s, :verbose=>false
-          Java.javadoc source_files, options.merge(:classpath=>classpath, :sourcepath=>sourcepath, :name=>name, :output=>target.to_s)
+          Java.javadoc source_files, options.merge(:classpath=>classpath, :sourcepath=>sourcepath,
+            :name=>name, :output=>File.expand_path(target.to_s))
           touch target.to_s, :verbose=>false
         end
       end
@@ -108,8 +109,7 @@
       # For example:
       #   package :zip, :classifier=>"docs", :include=>javadoc.target
       def into(path)
-        path = File.expand_path(path.to_s)
-        @target = file(path).enhance([self]) unless @target && @target.to_s == path
+        @target = file(path.to_s).enhance([self]) unless @target && @target.to_s == path.to_s
         self
       end
 
@@ -264,7 +264,7 @@
       sources = compile.sources if sources.empty?
       file(path_to(:target, "generated/apt")=>sources) do |task|
         Java.apt(sources.map(&:to_s) - [task.name], :output=>task.name,
-          :classpath=>compile.classpath, :source=>compile.options.source)
+          :classpath=>compile.dependencies, :source=>compile.options.source)
       end
     end
 

Modified: incubator/buildr/trunk/lib/java/packaging.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/packaging.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/packaging.rb (original)
+++ incubator/buildr/trunk/lib/java/packaging.rb Sat Jan  5 02:06:53 2008
@@ -1,16 +1,13 @@
-require "core/project"
-require "core/compile"
-require "core/test"
-require "java/artifact"
-require "java/java"
-require "tasks/zip"
-require "tasks/tar"
+require 'core/package'
+require 'java/java'
+require 'tasks/zip'
+require 'tasks/tar'
 
 
 module Buildr
   module Java
 
-    # Methods added to Project to support packaging.
+    # Adds packaging for Java projects: JAR, WAR, AAR, EAR, Javadoc.
     module Packaging
 
       # Adds support for MANIFEST.MF and other META-INF files.
@@ -20,7 +17,7 @@
           base.send :alias_method_chain, :initialize, :manifest
         end
 
-        MANIFEST_HEADER = ["Manifest-Version: 1.0", "Created-By: Buildr"]
+        MANIFEST_HEADER = ['Manifest-Version: 1.0', 'Created-By: Buildr']
 
         # Specifies how to create the manifest file.
         attr_accessor :manifest
@@ -35,19 +32,19 @@
 
           prepare do
             @prerequisites << manifest if String === manifest || Rake::Task === manifest
-            [meta_inf].flatten.map { |file| file.to_s }.uniq.each { |file| path("META-INF").include file }
+            [meta_inf].flatten.map { |file| file.to_s }.uniq.each { |file| path('META-INF').include file }
           end
 
           enhance do
             if manifest
               # Tempfiles gets deleted on garbage collection, so we're going to hold on to it
               # through instance variable not closure variable.
-              Tempfile.open "MANIFEST.MF" do |@manifest_tmp|
+              Tempfile.open 'MANIFEST.MF' do |@manifest_tmp|
                 lines = String === manifest || Rake::Task === manifest ? manifest_lines_from(File.read(manifest.to_s)) :
                   manifest_lines_from(manifest)
                 @manifest_tmp.write((MANIFEST_HEADER + lines).join("\n"))
                 @manifest_tmp.write "\n"
-                path("META-INF").include @manifest_tmp.path, :as=>"MANIFEST.MF"
+                path('META-INF').include @manifest_tmp.path, :as=>'MANIFEST.MF'
               end
             end
           end
@@ -62,22 +59,22 @@
               map { |line| manifest_wrap_at_72(line) }.flatten
           when Array
             arg.map { |section|
-              name = section.has_key?("Name") ? ["Name: #{section["Name"]}"] : []
-              name + section.except("Name").map { |name, value| "#{name}: #{value}" }.sort + [""]
+              name = section.has_key?('Name') ? ["Name: #{section['Name']}"] : []
+              name + section.except('Name').map { |name, value| "#{name}: #{value}" }.sort + ['']
             }.flatten.map { |line| manifest_wrap_at_72(line) }.flatten
           when Proc, Method
             manifest_lines_from(arg.call)
           when String
             arg.split("\n").map { |line| manifest_wrap_at_72(line) }.flatten
           else
-            fail "Invalid manifest, expecting Hash, Array, file name/task or proc/method."
+            fail 'Invalid manifest, expecting Hash, Array, file name/task or proc/method.'
           end
         end
 
         def manifest_wrap_at_72(arg)
           #return arg.map { |line| manifest_wrap_at_72(line) }.flatten.join("\n") if Array === arg
           return arg if arg.size < 72
-          [ arg[0..70], manifest_wrap_at_72(" " + arg[71..-1]) ]
+          [ arg[0..70], manifest_wrap_at_72(' ' + arg[71..-1]) ]
         end
 
       end
@@ -103,8 +100,8 @@
       # the META-INF directory.
       #
       # For example:
-      #   package(:jar).with(:manifest=>"src/MANIFEST.MF")
-      #   package(:jar).meta_inf << file("README")
+      #   package(:jar).with(:manifest=>'src/MANIFEST.MF')
+      #   package(:jar).meta_inf << file('README')
       class JarTask < ZipTask
 
         def initialize(*args) #:nodoc:
@@ -119,7 +116,7 @@
         # but other tasks (e.g. JarTask, WarTask) do.
         #
         # For example:
-        #   package(:jar).with(:manifest=>"MANIFEST_MF")
+        #   package(:jar).with(:manifest=>'MANIFEST_MF')
         def with(*args)
           super args.pop if Hash === args.last
           include :from=>args
@@ -137,7 +134,7 @@
       #   directory.
       #
       # For example:
-      #   package(:war).with(:libs=>"log4j:log4j:jar:1.1")
+      #   package(:war).with(:libs=>'log4j:log4j:jar:1.1')
       class WarTask < JarTask
 
         # Directories with class files to include under WEB-INF/classes.
@@ -151,8 +148,8 @@
           @classes = []
           @libs = []
           prepare do
-            @classes.to_a.flatten.each { |classes| path("WEB-INF/classes").include classes, :as=>"." }
-            path("WEB-INF/lib").include Buildr.artifacts(@libs) unless @libs.nil? || @libs.empty?
+            @classes.to_a.flatten.each { |classes| path('WEB-INF/classes').include classes, :as=>'.' }
+            path('WEB-INF/lib').include Buildr.artifacts(@libs) unless @libs.nil? || @libs.empty?
           end
         end
 
@@ -178,11 +175,11 @@
       # * :libs -- Array of files, tasks, artifact specifications, etc that will be added to the /lib directory.
       #
       # For example:
-      #   package(:aar).with(:libs=>"log4j:log4j:jar:1.1")
+      #   package(:aar).with(:libs=>'log4j:log4j:jar:1.1')
       #
-      #   filter.from("src/main/axis2").into("target").include("services.xml", "*.wsdl").using("http_port"=>"8080")
+      #   filter.from('src/main/axis2').into('target').include('services.xml', '*.wsdl').using('http_port'=>'8080')
       #   package(:aar).wsdls.clear
-      #   package(:aar).with(:services_xml=>_("target/services.xml"), :wsdls=>_("target/*.wsdl"))
+      #   package(:aar).with(:services_xml=>_('target/services.xml'), :wsdls=>_('target/*.wsdl'))
       class AarTask < JarTask
         # Artifacts to include under /lib.
         attr_accessor :libs
@@ -196,9 +193,9 @@
           @libs = []
           @wsdls = []
           prepare do
-            path("META-INF").include @wsdls
-            path("META-INF").include @services_xml, :as=>["services.xml"] if @services_xml
-            path("lib").include Buildr.artifacts(@libs) unless @libs.nil? || @libs.empty?
+            path('META-INF').include @wsdls
+            path('META-INF').include @services_xml, :as=>['services.xml'] if @services_xml
+            path('lib').include Buildr.artifacts(@libs) unless @libs.nil? || @libs.empty?
           end
         end
 
@@ -215,11 +212,6 @@
       include Extension
 
       before_define do |project|
-        # Need to run buildr before package, since package is often used as a dependency by tasks that
-        # expect build to happen.
-        project.task("package"=>project.task("build"))
-        project.group ||= project.parent && project.parent.group || project.name
-        project.version ||= project.parent && project.parent.version
         project.manifest ||= project.parent && project.parent.manifest ||
           { 'Build-By'=>ENV['USER'], 'Build-Jdk'=>Java.version,
             'Implementation-Title'=>project.comment || project.name,
@@ -229,22 +221,6 @@
       end
 
 
-      # Options accepted by #package method for all package types.
-      PACKAGE_OPTIONS = [:group, :id, :version, :type, :classifier] #:nodoc:
-
-      # The project's identifier. Same as the project name, with colons replaced by dashes.
-      # The ID for project foo:bar is foo-bar.
-      attr_reader :id
-      def id()
-        name.gsub(":", "-")
-      end
-
-      # Group used for packaging. Inherited from parent project. Defaults to the top-level project name.
-      attr_accessor :group
-
-      # Version used for packaging. Inherited from parent project.
-      attr_accessor :version
-
       # Manifest used for packaging. Inherited from parent project. The default value is a hash that includes
       # the Build-By, Build-Jdk, Implementation-Title and Implementation-Version values.
       # The later are taken from the project's comment (or name) and version number.
@@ -255,136 +231,12 @@
       attr_accessor :meta_inf
 
       # :call-seq:
-      #   package(type, spec?) => task
-      #
-      # Defines and returns a package created by this project.
-      #
-      # The first argument declares the package type. For example, :jar to create a JAR file.
-      # The package is an artifact that takes its artifact specification from the project.
-      # You can override the artifact specification by passing various options in the second
-      # argument, for example:
-      #   package(:zip, :classifier=>"sources")
-      #
-      # Packages that are ZIP files provides various ways to include additional files, directories,
-      # and even merge ZIPs together. Have a look at ZipTask for more information. In case you're
-      # wondering, JAR and WAR packages are ZIP files.
-      #
-      # You can also enhance a JAR package using the ZipTask#with method that accepts the following options:
-      # * :manifest -- Specifies how to create the MANIFEST.MF. By default, uses the project's
-      #   #manifest property.
-      # * :meta_inf -- Specifies files to be included in the META-INF directory. By default,
-      #   uses the project's #meta-inf property.
-      #
-      # The WAR package supports the same options and adds a few more:
-      # * :classes -- Directories of class files to include in WEB-INF/classes. Includes the compile
-      #   target directory by default.
-      # * :libs -- Artifacts and files to include in WEB-INF/libs. Includes the compile classpath
-      #   dependencies by default.
-      #
-      # For example:
-      #   define "project" do
-      #     define "beans" do
-      #       package :jar
-      #     end
-      #     define "webapp" do
-      #       compile.with project("beans")
-      #       package(:war).with :libs=>MYSQL_JDBC
-      #     end
-      #     package(:zip, :classifier=>"sources").include path_to(".")
-      #  end
-      #
-      # Two other packaging types are:
-      # * package :sources -- Creates a ZIP file with the source code and classifier "sources", for use by IDEs.
-      # * package :javadoc -- Creates a ZIP file with the Javadocs and classifier "javadoc". You can use the
-      #   javadoc method to further customize it.
-      #
-      # A package is also an artifact. The following tasks operate on packages created by the project:
-      #   buildr upload     # Upload packages created by the project
-      #   buildr install    # Install packages created by the project
-      #   buildr package    # Create packages
-      #   buildr uninstall  # Remove previously installed packages
-      #
-      # If you want to add additional packaging types, implement a method with the name package_as_[type]
-      # that accepts two arguments, the file name and a hash of options. You can change the options and
-      # file name, e.g. to add a classifier or change the file type. Your method may be called multiple times,
-      # and must return the same file task on each call.
-      def package(type = :jar, options = nil)
-        options = options.nil? ? {} : options.dup
-        rake_check_options options, *ActsAsArtifact::ARTIFACT_ATTRIBUTES
-        options[:id] ||= self.id
-        options[:group] ||= self.group
-        options[:version] ||= self.version
-        options[:type] = type
-        file_name = path_to(:target, Artifact.hash_to_file_name(options))
-
-        packager = method("package_as_#{type}") rescue
-          fail("Don't know how to create a package of type #{type}")
-        package = packager.call(file_name, options)
-        unless packages.include?(package)
-          # Make it an artifact using the specifications, and tell it how to create a POM.
-          package.extend ActsAsArtifact
-          package.send :apply_spec, options.only(*Artifact::ARTIFACT_ATTRIBUTES)
-          # Another task to create the POM file.
-          pom = package.pom
-          pom.enhance do
-            mkpath File.dirname(pom.name), :verbose=>false
-            File.open(pom.name, "w") { |file| file.write pom.pom_xml }
-          end
-
-          # We already run build before package, but we also need to do so if the package itself is
-          # used as a dependency, before we get to run the package task.
-          task "package"=>package
-          package.enhance [task("build")]
-
-          # Install the artifact along with its POM. Since the artifact (package task) is created
-          # in the target directory, we need to copy it into the local repository. However, the
-          # POM artifact (created by calling artifact on its spec) is already mapped to its right
-          # place in the local repository, so we only need to invoke it.
-          installed = file(Buildr.repositories.locate(package)=>package) { |task|
-            verbose(Rake.application.options.trace || false) do
-              mkpath File.dirname(task.name), :verbose=>false
-              cp package.name, task.name
-            end
-            puts "Installed #{task.name}" if verbose
-          }
-          task "install"=>[installed, pom]
-          task "uninstall" do |task|
-            verbose(Rake.application.options.trace || false) do
-              [ installed, pom ].map(&:to_s).each { |file| rm file if File.exist?(file) } 
-            end
-          end
-          task("upload") { package.pom.invoke ; package.pom.upload ; package.upload }
-
-          # Add the package to the list of packages created by this project, and
-          # register it as an artifact. The later is required so if we look up the spec
-          # we find the package in the project's target directory, instead of finding it
-          # in the local repository and attempting to install it.
-          packages << package
-          Artifact.register package, pom
-        end
-        package
-      end
-
-      # :call-seq:
-      #   packages() => tasks
-      #
-      # Returns all packages created by this project. A project may create any number of packages.
-      #
-      # This method is used whenever you pass a project to Buildr#artifact or any other method
-      # that accepts artifact specifications and projects. You can use it to list all packages
-      # created by the project. If you want to return a specific package, it is often more
-      # convenient to call #package with the type.
-      def packages()
-        @packages ||= []
-      end
-
-      # :call-seq:
       #   package_with_sources(options?)
       #
       # Call this when you want the project (and all its sub-projects) to create a source distribution.
       # You can use the source distribution in an IDE when debugging.
       #
-      # A source distribution is a ZIP package with the classifier "sources", which includes all the
+      # A source distribution is a ZIP package with the classifier 'sources', which includes all the
       # sources used by the compile task.
       #
       # Packages use the project's manifest and meta_inf properties, which you can override by passing
@@ -392,7 +244,7 @@
       #
       # To create source distributions only for specific projects, use the :only and :except options,
       # for example:
-      #   package_with_sources :only=>["foo:bar", "foo:baz"]
+      #   package_with_sources :only=>['foo:bar', 'foo:baz']
       #
       # (Same as calling package :sources on each project/sub-project that has source directories.)
       def package_with_sources(options = nil)
@@ -412,7 +264,7 @@
       # Call this when you want the project (and all its sub-projects) to create a JavaDoc distribution.
       # You can use the JavaDoc distribution in an IDE when coding against the API.
       #
-      # A JavaDoc distribution is a ZIP package with the classifier "javadoc", which includes all the
+      # A JavaDoc distribution is a ZIP package with the classifier 'javadoc', which includes all the
       # sources used by the compile task.
       #
       # Packages use the project's manifest and meta_inf properties, which you can override by passing
@@ -420,7 +272,7 @@
       #
       # To create JavaDoc distributions only for specific projects, use the :only and :except options,
       # for example:
-      #   package_with_javadoc :only=>["foo:bar", "foo:baz"]
+      #   package_with_javadoc :only=>['foo:bar', 'foo:baz']
       #
       # (Same as calling package :javadoc on each project/sub-project that has source directories.)
       def package_with_javadoc(options = nil)
@@ -436,80 +288,55 @@
 
     protected
 
-      def package_as_jar(file_name, spec) #:nodoc:
-        unless Rake::Task.task_defined?(file_name)
-          Java::Packaging::JarTask.define_task(file_name).tap do |jar|
-            jar.with :manifest=>manifest, :meta_inf=>meta_inf
-            jar.with compile.target unless compile.sources.empty?
-            jar.with resources.target unless resources.sources.empty?
-          end
+      def package_as_jar(file_name) #:nodoc:
+        Java::Packaging::JarTask.define_task(file_name).tap do |jar|
+          jar.with :manifest=>manifest, :meta_inf=>meta_inf
+          jar.with compile.target unless compile.sources.empty?
+          jar.with resources.target unless resources.sources.empty?
         end
-        file(file_name)
       end
 
-      def package_as_war(file_name, spec) #:nodoc:
-        unless Rake::Task.task_defined?(file_name)
-          Java::Packaging::WarTask.define_task(file_name).tap do |war|
-            war.with :manifest=>manifest, :meta_inf=>meta_inf
-            # Add libraries in WEB-INF lib, and classes in WEB-INF classes
-            war.with :classes=>compile.target unless compile.sources.empty?
-            war.with :classes=>resources.target unless resources.sources.empty?
-            war.with :libs=>compile.dependencies
-            # Add included files, or the webapp directory.
-            webapp = path_to(:source, :main, :webapp)
-            war.with webapp if File.exist?(webapp)
-          end
+      def package_as_war(file_name) #:nodoc:
+        Java::Packaging::WarTask.define_task(file_name).tap do |war|
+          war.with :manifest=>manifest, :meta_inf=>meta_inf
+          # Add libraries in WEB-INF lib, and classes in WEB-INF classes
+          war.with :classes=>compile.target unless compile.sources.empty?
+          war.with :classes=>resources.target unless resources.sources.empty?
+          war.with :libs=>compile.dependencies
+          # Add included files, or the webapp directory.
+          webapp = path_to(:source, :main, :webapp)
+          war.with webapp if File.exist?(webapp)
         end
-        file(file_name)
       end
 
-      def package_as_aar(file_name, spec) #:nodoc:
-        unless Rake::Task.task_defined?(file_name)
-          Java::Packaging::AarTask.define_task(file_name).tap do |aar|
-            aar.with :manifest=>manifest, :meta_inf=>meta_inf
-            aar.with :wsdls=>path_to(:source, :main, :axis2, '*.wsdl')
-            aar.with :services_xml=>path_to(:source, :main, :axis2, 'services.xml') 
-            aar.with compile.target unless compile.sources.empty?
-            aar.with resources.target unless resources.sources.empty?
-            aar.with :libs=>compile.dependencies
-          end
+      def package_as_aar(file_name) #:nodoc:
+        Java::Packaging::AarTask.define_task(file_name).tap do |aar|
+          aar.with :manifest=>manifest, :meta_inf=>meta_inf
+          aar.with :wsdls=>path_to(:source, :main, :axis2, '*.wsdl')
+          aar.with :services_xml=>path_to(:source, :main, :axis2, 'services.xml') 
+          aar.with compile.target unless compile.sources.empty?
+          aar.with resources.target unless resources.sources.empty?
+          aar.with :libs=>compile.dependencies
         end
-        file(file_name)
       end
 
-      def package_as_zip(file_name, spec) #:nodoc:
-        ZipTask.define_task(file_name)
+      def package_as_javadoc_spec(spec) #:nodoc:
+        spec.merge(:type=>:zip, :classifier=>'javadoc')
       end
 
-      def package_as_tar(file_name, spec) #:nodoc:
-        TarTask.define_task(file_name)
-      end
-      alias :package_as_tgz :package_as_tar
-
-      def package_as_sources(file_name, spec) #:nodoc:
-        spec.merge!(:type=>:zip, :classifier=>"sources")
-        file_name = path_to(:target, Artifact.hash_to_file_name(spec))
-        unless Rake::Task.task_defined?(file_name)
-          ZipTask.define_task(file_name).tap do |zip|
-            zip.include :from=>compile.sources
-          end
-        end
-        file(file_name)
-      end
-
-      def package_as_javadoc(file_name, spec) #:nodoc:
-        spec.merge!(:type=>:zip, :classifier=>"javadoc")
-        file_name = path_to(:target, Artifact.hash_to_file_name(spec))
-        unless Rake::Task.task_defined?(file_name)
-          ZipTask.define_task(file_name).tap do |zip|
-            zip.include :from=>javadoc.target
-          end
+      def package_as_javadoc(file_name) #:nodoc:
+        ZipTask.define_task(file_name).tap do |zip|
+          zip.include :from=>javadoc.target
           javadoc.options[:windowtitle] ||= project.comment || project.name
         end
-        file(file_name)
       end
 
     end
 
   end
+end
+
+
+class Buildr::Project
+  include Buildr::Java::Packaging
 end

Modified: incubator/buildr/trunk/lib/java/test_frameworks.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/test_frameworks.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/test_frameworks.rb (original)
+++ incubator/buildr/trunk/lib/java/test_frameworks.rb Sat Jan  5 02:06:53 2008
@@ -112,6 +112,10 @@
       super(path).reject { |name| name =~ /\$/ }
     end
 
+    def supports?(project) #:nodoc:
+      project.test.compile.language == :java
+    end
+
     def run(files, task, dependencies) #:nodoc:
       # Use Ant to execute the Junit tasks, gives us performance and reporting.
       Buildr.ant('junit') do |ant|
@@ -192,6 +196,10 @@
       super :requires=>REQUIRES, :patterns=>TESTS_PATTERN
     end
 
+    def supports?(project) #:nodoc:
+      project.test.compile.language == :java
+    end
+
     def files(path) #:nodoc:
       # Ignore anonymous classes.
       super(path).reject { |name| name =~ /\$/ }
@@ -217,5 +225,5 @@
 end
 
 
-Buildr::TestFramework.add Buildr::TestNG
 Buildr::TestFramework.add Buildr::JUnit
+Buildr::TestFramework.add Buildr::TestNG

Modified: incubator/buildr/trunk/spec/archive_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/archive_spec.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/archive_spec.rb (original)
+++ incubator/buildr/trunk/spec/archive_spec.rb Sat Jan  5 02:06:53 2008
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'sandbox')
+require File.join(File.dirname(__FILE__), 'spec_helpers')
 
 
 describe "ArchiveTask", :shared=>true do

Modified: incubator/buildr/trunk/spec/artifact_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/artifact_spec.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/artifact_spec.rb (original)
+++ incubator/buildr/trunk/spec/artifact_spec.rb Sat Jan  5 02:06:53 2008
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'sandbox')
+require File.join(File.dirname(__FILE__), 'spec_helpers')
 
 
 describe Artifact do

Modified: incubator/buildr/trunk/spec/build_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/build_spec.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/build_spec.rb (original)
+++ incubator/buildr/trunk/spec/build_spec.rb Sat Jan  5 02:06:53 2008
@@ -1,4 +1,5 @@
-require File.join(File.dirname(__FILE__), 'sandbox')
+require File.join(File.dirname(__FILE__), 'spec_helpers')
+
 
 describe 'local task', :shared=>true do
   it "should execute task for project in current directory" do
@@ -145,7 +146,7 @@
 
   it 'should set layout :target' do
     @project.target = 'bar'
-    @project.layout.expand(:target).should eql(File.expand_path('bar'))
+    @project.layout.expand(:target).should point_to_path('bar')
   end
 
   it 'should come from layout :target' do
@@ -166,7 +167,7 @@
 
   it 'should set layout :reports' do
     @project.reports = 'bar'
-    @project.layout.expand(:reports).should eql(File.expand_path('bar'))
+    @project.layout.expand(:reports).should point_to_path('bar')
   end
 
   it 'should come from layout :reports' do

Modified: incubator/buildr/trunk/spec/checks_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/checks_spec.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/checks_spec.rb (original)
+++ incubator/buildr/trunk/spec/checks_spec.rb Sat Jan  5 02:06:53 2008
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'sandbox')
+require File.join(File.dirname(__FILE__), 'spec_helpers')
 
 
 describe Project, " check task" do

Modified: incubator/buildr/trunk/spec/common_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/common_spec.rb?rev=609118&r1=609117&r2=609118&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/common_spec.rb (original)
+++ incubator/buildr/trunk/spec/common_spec.rb Sat Jan  5 02:06:53 2008
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'sandbox')
+require File.join(File.dirname(__FILE__), 'spec_helpers')
 
 
 describe Buildr.method(:struct) do
@@ -178,25 +178,25 @@
 
 
 describe Buildr.method(:filter) do
-  before do
-    @src = File.expand_path("src") 
+  def source
+    File.expand_path("src")
   end
   
   it "should return a Filter for the source" do
-    filter(@src).should be_kind_of(Filter)
+    filter(source).should be_kind_of(Filter)
   end
 
   it "should use the source directory" do
-    filter(@src).sources.should include(file(@src))
+    filter(source).sources.should include(file(source))
   end
 
   it "should use the source directories" do
     dirs = ["first", "second"]
-    filter("first", "second").sources.should include(*dirs.map { |dir| file(File.expand_path(dir)) })
+    filter("first", "second").sources.should include(*dirs.map { |dir| file(dir) })
   end
 
   it "should accept a file task" do
-    task = file(@src)
+    task = file(source)
     filter(task).sources.each { |source| source.should be(task) }
   end
 end
@@ -220,7 +220,7 @@
   it "should respond to :from and add source directories" do
     dirs = ["first", "second"]
     @filter.from(*dirs)
-    @filter.sources.should include(*dirs.map { |dir| file(File.expand_path(dir)) })
+    @filter.sources.should include(*dirs.map { |dir| file(dir) })
   end
 
   it "should return source directories as file task" do
@@ -228,7 +228,7 @@
   end
 
   it "should return source directories as expanded path" do
-    @filter.from("src").sources.each { |source| source.to_s.should eql(File.expand_path("src")) }
+    @filter.from("src").sources.each { |source| source.to_s.should eql("src") }
   end
 
   it "should respond to :into and return self" do
@@ -237,7 +237,7 @@
 
   it "should respond to :into and set target directory" do
     lambda { @filter.into("src") }.should change { @filter.target }
-    @filter.into("target").target.should be(file(File.expand_path("target")))
+    @filter.into("target").target.should be(file('target'))
   end
 
   it "should return target directory as file task" do
@@ -245,7 +245,7 @@
   end
 
   it "should return target directory as expanded path" do
-    @filter.into("target").target.to_s.should eql(File.expand_path("target"))
+    @filter.into("target").target.to_s.should eql('target')
   end
 
   it "should respond to :using and return self" do
@@ -541,10 +541,6 @@
 
 
 describe Buildr, 'profiles' do
-  before :each do
-    Rake.application.instance_eval { @rakefile = File.expand_path('buildfile') }
-  end
-
   it 'should return empty hash if no profiles file' do
     Buildr.profiles.should == {}
   end
@@ -562,10 +558,6 @@
 
 
 describe Buildr, 'profile' do
-  before :each do
-    Rake.application.instance_eval { @rakefile = File.expand_path('buildfile') }
-  end
-
   it 'should return profile for current environment' do
     Buildr.environment = 'qa'
     Buildr.profiles['qa'] = { 'foo'=>'bar' }



Mime
View raw message