You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by do...@apache.org on 2013/08/14 03:23:28 UTC
svn commit: r1513707 - in /buildr/trunk: CHANGELOG addon/buildr/gwt.rb
doc/packaging.textile lib/buildr.rb lib/buildr/core/assets.rb
lib/buildr/ide/idea.rb lib/buildr/java/packaging.rb
spec/java/packaging_spec.rb
Author: donaldp
Date: Wed Aug 14 01:23:28 2013
New Revision: 1513707
URL: http://svn.apache.org/r1513707
Log:
Initial support for simple integration of an asset pipeline.
See "Compiling Assets" section in the manual.
Added:
buildr/trunk/lib/buildr/core/assets.rb
Modified:
buildr/trunk/CHANGELOG
buildr/trunk/addon/buildr/gwt.rb
buildr/trunk/doc/packaging.textile
buildr/trunk/lib/buildr.rb
buildr/trunk/lib/buildr/ide/idea.rb
buildr/trunk/lib/buildr/java/packaging.rb
buildr/trunk/spec/java/packaging_spec.rb
Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1513707&r1=1513706&r2=1513707&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Wed Aug 14 01:23:28 2013
@@ -1,4 +1,6 @@
1.4.13 (Pending)
+* Added: Initial support for simple integration of an asset pipeline.
+ See "Compiling Assets" section in the manual.
* Fixed: BUILDR-673 - Fix the option handling of the MultiTest test
framework to behave as documented. Only the framework specific
options are passed to the test. Submitted by John Roth.
Modified: buildr/trunk/addon/buildr/gwt.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/addon/buildr/gwt.rb?rev=1513707&r1=1513706&r2=1513707&view=diff
==============================================================================
--- buildr/trunk/addon/buildr/gwt.rb (original)
+++ buildr/trunk/addon/buildr/gwt.rb Wed Aug 14 01:23:28 2013
@@ -105,6 +105,7 @@ module Buildr
end
task.enhance(dependencies)
task.enhance([project.compile])
+ project.assets.paths << task
task
end
Modified: buildr/trunk/doc/packaging.textile
URL: http://svn.apache.org/viewvc/buildr/trunk/doc/packaging.textile?rev=1513707&r1=1513706&r2=1513707&view=diff
==============================================================================
--- buildr/trunk/doc/packaging.textile (original)
+++ buildr/trunk/doc/packaging.textile Wed Aug 14 01:23:28 2013
@@ -235,6 +235,35 @@ puts 'Artifacts included in WAR package:
puts package(:war).libs.map(&:to_spec)
{% endhighlight %}
+h3(#war_extra_assets). Compiling Assets
+
+In modern web applications, it is common to use tools that compile and compress assets. i.e. "Coffeescript":http://coffeescript.org/ is compiled into javascript and "Sass":http://sass-lang.com/ compiles into CSS. Buildr provides support using a simple @assets@ abstraction. Directory or file tasks can be added to the @assets.paths@ configuration variable for a project and the contents will be included in the package.
+
+h4(#coffeescript). Integrating CoffeeScript
+
+{% highlight ruby %}
+target_dir = _(:target, :generated, "coffee/main/webapp")
+source_dir = _(:source, :main, :coffee)
+
+assets.paths << file(target_dir => [FileList["#{source_dir}/**/*.coffee"]]) do
+ puts "Compiling coffeescript"
+ sh "coffee --bare --compile --output #{target_dir} #{source_dir}"
+ touch target_dir
+end
+{% endhighlight %}
+
+h4(#sass). Integrating Sass
+
+{% highlight ruby %}
+target_dir = _(:target, :generated, "sass/main/webapp")
+source_dir = _(:source, :main, :sass)
+
+assets.paths << file(target_dir => [FileList["#{source_dir}/**/*.scss"]]) do
+ puts "Compiling scss"
+ sh "scss -q --update #{source_dir}:#{target_dir}"
+ touch target_dir
+end
+{% endhighlight %}
h2(#aar). Packaging AARs
Modified: buildr/trunk/lib/buildr.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr.rb?rev=1513707&r1=1513706&r2=1513707&view=diff
==============================================================================
--- buildr/trunk/lib/buildr.rb (original)
+++ buildr/trunk/lib/buildr.rb Wed Aug 14 01:23:28 2013
@@ -42,6 +42,7 @@ require 'buildr/core/common'
require 'buildr/core/application'
require 'buildr/core/jrebel'
require 'buildr/core/project'
+require 'buildr/core/assets'
require 'buildr/core/environment'
require 'buildr/core/help'
require 'buildr/core/checks'
Added: buildr/trunk/lib/buildr/core/assets.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/assets.rb?rev=1513707&view=auto
==============================================================================
--- buildr/trunk/lib/buildr/core/assets.rb (added)
+++ buildr/trunk/lib/buildr/core/assets.rb Wed Aug 14 01:23:28 2013
@@ -0,0 +1,93 @@
+# 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 #:nodoc:
+
+ module Assets #:nodoc:
+
+ # The base assets task that is responsible for
+ # collecting all of the assets into a single output
+ # directory
+ class AssetsTask < Rake::FileTask
+ attr_reader :project
+
+ def project=(project)
+ @project = project
+ end
+
+ # The list of input paths to add to output directory
+ def paths
+ unless @paths
+ @paths = []
+ @paths << project._(:source, :main, :webapp) if File.exist?(project._(:source, :main, :webapp))
+ end
+ @paths
+ end
+
+ protected
+
+ def initialize(*args) #:nodoc:
+ super
+ enhance do
+ mkdir_p name
+ self.paths.flatten.compact.collect do |a|
+ a.is_a?(String) ? project.file(a) : a
+ end.each do |a|
+ a.invoke if a.respond_to?(:invoke)
+ end.each do |asset|
+ cp_r Dir["#{asset}/*"], "#{name}/"
+ end
+ end
+ end
+
+ private
+
+ def out_of_date?(stamp)
+ super ||
+ self.paths.any? { |n| n.respond_to?(:needed?) && n.needed? }
+ end
+
+ end
+
+ module ProjectExtension
+ include Extension
+
+ first_time do
+ desc "Prepare the assets"
+ Project.local_task("assets")
+ end
+
+ # Access the asset task
+ def assets
+ if @assets.nil?
+ @assets = AssetsTask.define_task(project._(:target, :main, :webapp) => [])
+ @assets.project = self
+ project.task('assets').enhance([@assets])
+ project.build.enhance([@assets])
+ end
+ @assets
+ end
+
+ after_define do |project|
+ # Force construction
+ project.assets
+ end
+ end
+ end
+end
+
+class Buildr::Project #:nodoc:
+ include ::Buildr::Assets::ProjectExtension
+end
Modified: buildr/trunk/lib/buildr/ide/idea.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/ide/idea.rb?rev=1513707&r1=1513706&r2=1513707&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/ide/idea.rb (original)
+++ buildr/trunk/lib/buildr/ide/idea.rb Wed Aug 14 01:23:28 2013
@@ -299,7 +299,7 @@ module Buildr #:nodoc:
def add_web_facet(options = {})
name = options[:name] || "Web"
url_base = options[:url_base] || "/"
- default_webroots = [buildr_project._(:source, :main, :webapp)]
+ default_webroots = project.assets.paths
webroots = options[:webroots] || default_webroots
default_web_xml = "#{buildr_project._(:source, :main, :webapp)}/WEB-INF/web.xml"
web_xml = options[:web_xml] || default_web_xml
Modified: buildr/trunk/lib/buildr/java/packaging.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/java/packaging.rb?rev=1513707&r1=1513706&r2=1513707&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/java/packaging.rb (original)
+++ buildr/trunk/lib/buildr/java/packaging.rb Wed Aug 14 01:23:28 2013
@@ -685,8 +685,12 @@ module Buildr #:nodoc:
war.with :classes=>[compile.target, resources.target].compact
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)
+ assets.paths.each do |asset|
+ war.tap do |war|
+ war.enhance([asset])
+ end
+ war.include asset, :as => '.'
+ end
end
end
Modified: buildr/trunk/spec/java/packaging_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/java/packaging_spec.rb?rev=1513707&r1=1513706&r2=1513707&view=diff
==============================================================================
--- buildr/trunk/spec/java/packaging_spec.rb (original)
+++ buildr/trunk/spec/java/packaging_spec.rb Wed Aug 14 01:23:28 2013
@@ -530,6 +530,26 @@ describe Packaging, 'war' do
inspect_war { |files| files.should include('test.html') }
end
+ it 'should use files from added assets directory if nothing included' do
+ write 'generated/main/webapp/test.html'
+ define('foo', :version => '1.0') { assets.paths << 'generated/main/webapp/'; package(:war) }
+ inspect_war { |files| files.should include('test.html') }
+ end
+
+ it 'should use files from generated assets directory if nothing included' do
+ write 'generated/main/webapp/test.html'
+ define('foo', :version => '1.0') do
+ target_dir = _('generated/main/webapp')
+ assets.paths << project.file(target_dir) do
+ mkdir_p target_dir
+ touch "#{target_dir}/test.html"
+ touch target_dir
+ end
+ package(:war)
+ end
+ inspect_war { |files| files.should include('test.html') }
+ end
+
it 'should accept files from :classes option' do
write 'src/main/java/Test.java', 'class Test {}'
write 'classes/test'