1 && args[1].equals("-c"));
33 | String spec = colors ? args[2] : args[1];
34 |
35 | run(args[0], colors, spec);
36 | }
37 |
38 | // Incompatible with JVM 1.4 target
39 | // @throws(classOf[Throwable])
40 | static void run(String path, boolean colors, String spec) {
41 | try {
42 | File parent = new File(path);
43 | URL specURL = new File(parent, spec.replace('.', '/') + ".class").toURL();
44 | URLClassLoader loader = new URLClassLoader(new URL[] { specURL }, Thread.currentThread().getContextClassLoader());
45 |
46 | Class clazz = loader.loadClass(spec);
47 | Object instance = clazz.getField("MODULE$").get(null);
48 |
49 | Method main = clazz.getMethod("main", String[].class);
50 |
51 | String[] args = colors ? new String[] { "-c" } : new String[] {};
52 | main.invoke(instance, new Object[] { args });
53 | } catch (Exception e) {
54 | throw new RuntimeException(e);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/doc/preface.textile:
--------------------------------------------------------------------------------
1 | ---
2 | layout: preface
3 | ---
4 |
5 | p(title). !images/zbuildr.png!
6 |
7 |
8 | - "Quick Start":quick_start.html
9 | - "Installing and Running":installing.html
10 | - "Projects":projects.html
11 | - "Building":building.html
12 | - "Artifacts":artifacts.html
13 | - "Packaging":packaging.html
14 | - "Testing":testing.html
15 | - "Settings & Profiles":settings_profiles.html
16 | - "Languages":languages.html
17 | - "More Stuff":more_stuff.html
18 | - "Extending Buildr":extending.html
19 | - "Contributing":contributing.html
20 |
21 |
22 |
23 | p(preface). !images/asf-logo.png!
24 |
25 | Copyright 2007-2009 Apache Buildr
26 |
27 | Licensed 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
28 |
29 | http://www.apache.org/licenses/LICENSE-2.0
30 |
31 | 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.
32 |
33 |
34 |
35 |
36 | "Daniel Spiewak":http://www.codecommit.com/blog:
37 |
38 | bq. If you think about it, the question isn’t “Why use Buildr?”, it’s really “Why use anything else?” The advantages afforded by Buildr are so substantial, I really can’t see myself going with any other tool, at least not when I have a choice.
39 |
40 | "Tristan Juricek":http://tristanhunt.com/:
41 |
42 | bq. That’s still the strongest sell: it builds everything I need, and as I’ve needed more, I just got things working without a lot of fuss.
43 |
44 | "Matthieu Riou":http://offthelip.org/:
45 |
46 | bq. We used to rely on Ant, with a fairly extensive set of scripts. It worked but was expensive to maintain. The biggest mistake afterward was to migrate to Maven2. I could write pages of rants explaining all the problems we ran into and we still ended up with thousands of lines of XML.
47 |
48 | "Martin Grotzke":http://www.javakaffee.de/blog/:
49 |
50 | bq. The positive side effect for me as a java user is that I learn a little ruby, and that’s easy but lots of fun… :-)
51 |
52 |
53 |
54 | p(preface).
55 |
--------------------------------------------------------------------------------
/rakelib/package.rake:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | require 'rubygems/package_task'
17 |
18 | Gem::PackageTask.new(spec) do |pkg|
19 | pkg.need_tar = true
20 | pkg.need_zip = true
21 | end
22 |
23 | desc 'Compile Java libraries used by Buildr'
24 | task 'compile' do
25 | puts 'Compiling Java libraries ...'
26 | args = RbConfig::CONFIG['ruby_install_name'], File.expand_path(RUBY_PLATFORM[/java/] ? '_jbuildr' : '_buildr'), '--buildfile', 'buildr.buildfile', 'compile'
27 | args << '--trace' if Rake.application.options.trace
28 | sh *args
29 | end
30 | file Gem::PackageTask.new(spec).package_dir => 'compile'
31 | file Gem::PackageTask.new(spec).package_dir_path => 'compile'
32 |
33 | # We also need the other packages (JRuby if building on Ruby, and vice versa)
34 | # Must call new with block, even if block does nothing, otherwise bad things happen.
35 | @specs.values.each do |s|
36 | Gem::PackageTask.new(s) { |task| }
37 | end
38 |
39 | desc 'Upload snapshot packages over to people.apache.org'
40 | task 'snapshot' => %w(package) do
41 | rm_rf '_snapshot' # Always start with empty directory
42 | puts 'Copying existing gems from Apache'
43 | sh 'rsync', '--progress', '--recursive', 'people.apache.org:public_html/buildr/snapshot/', '_snapshot/'
44 | puts 'Copying new gems over'
45 | cp FileList['pkg/{*.gem,*.tgz,*.zip}'], '_snapshot/gems'
46 | puts 'Generating gem index ...'
47 | sh 'gem', 'generate_index', '--directory', '_snapshot'
48 | puts 'Copying gem and index back to Apache'
49 | sh 'rsync', '--progress', '--recursive', '_snapshot/', 'people.apache.org:public_html/buildr/snapshot/'
50 | end
51 | task('clobber') { rm_rf 'target' }
52 | task('clobber') { rm_rf '_snapshot' }
53 |
--------------------------------------------------------------------------------
/spec/core/console_spec.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
17 |
18 | describe Buildr::Console do
19 |
20 | describe 'console_dimensions' do
21 |
22 | it 'should return a value' do
23 | Buildr::Console.console_dimensions.should_not be_nil
24 | end if $stdout.isatty && !ENV["TRAVIS"] && !Buildr::Util.win_os?
25 | end
26 |
27 | describe 'color' do
28 |
29 | describe 'when use_color is true' do
30 | before do
31 | Buildr::Console.use_color = true
32 | end
33 |
34 | it 'should emit red code when asked' do
35 | Buildr::Console.color('message', :red).should eql("\e[31mmessage\e[0m")
36 | end
37 |
38 | it 'should emit green code when asked' do
39 | Buildr::Console.color('message', :green).should eql("\e[32mmessage\e[0m")
40 | end
41 |
42 | it 'should emit blue code when asked' do
43 | Buildr::Console.color('message', :blue).should eql("\e[34mmessage\e[0m")
44 | end
45 | end if $stdout.isatty && !Buildr::Util.win_os?
46 |
47 | describe ' use_color is false' do
48 | before do
49 | Buildr::Console.use_color = false
50 | end
51 |
52 | it 'should not emit red code when asked' do
53 | Buildr::Console.color('message', :red).should eql("message")
54 | end
55 |
56 | it 'should not emit green code when asked' do
57 | Buildr::Console.color('message', :green).should eql("message")
58 | end
59 |
60 | it 'should not emit blue code when asked' do
61 | Buildr::Console.color('message', :blue).should eql("message")
62 | end
63 | end
64 | end
65 | end
66 |
--------------------------------------------------------------------------------
/spec/java/external_spec.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 |
17 | require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18 |
19 | COMPILERS = Buildr::Compiler.compilers.dup
20 | COMPILERS_WITHOUT_JAVAC = COMPILERS.dup
21 | COMPILERS_WITHOUT_JAVAC.delete Buildr::Compiler::Javac
22 |
23 | describe Buildr::Compiler::ExternalJavac do
24 |
25 | before(:all) do
26 | Buildr::Compiler.send :compilers=, COMPILERS_WITHOUT_JAVAC
27 | end
28 |
29 | # Fails sometimes under windows?
30 | describe "should compile a Java project just in the same way javac does", :retry => 4 do
31 | javac_spec = File.read(File.join(File.dirname(__FILE__), "compiler_spec.rb"))
32 | javac_spec = javac_spec.match(Regexp.escape("require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))\n")).post_match
33 | javac_spec.gsub!("javac", "externaljavac")
34 | javac_spec.gsub!("--trace=externaljavac", "--trace=javac")
35 | javac_spec.gsub!("trace_categories = [:externaljavac]", "trace_categories = [:javac]")
36 | eval(javac_spec)
37 | end
38 |
39 | it "should accept a :jvm option as JAVA_HOME" do
40 | write 'src/main/java/Foo.java', 'public class Foo {}'
41 | define "foo" do
42 | compile.using(:externaljavac).options.jvm = "somepath"
43 | end
44 | begin
45 | trace true #We set it true to grab the trace statement with the jvm path in it!
46 | lambda {lambda {project("foo").compile.invoke}.should raise_error(RuntimeError, /Failed to compile, see errors above/)}.should show(/somepath\/bin\/javac .*/)
47 | end
48 | trace false
49 | end
50 |
51 | after :all do
52 | Buildr::Compiler.send :compilers=, COMPILERS
53 | end
54 |
55 | end
56 |
--------------------------------------------------------------------------------
/spec/packaging/packaging_helper.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 |
17 | shared_examples_for 'packaging' do
18 | it 'should create artifact of proper type' do
19 | packaging = @packaging
20 | package_type = @package_type || @packaging
21 | define 'foo', :version=>'1.0' do
22 | package(packaging).type.should eql(package_type) rescue exit!
23 | end
24 | end
25 |
26 | it 'should create file with proper extension' do
27 | packaging = @packaging
28 | package_type = @package_type || @packaging
29 | define 'foo', :version=>'1.0' do
30 | package(packaging).to_s.should match(/.#{package_type}$/)
31 | end
32 | end
33 |
34 | it 'should always return same task for the same package' do
35 | packaging = @packaging
36 | define 'foo', :version=>'1.0' do
37 | package(packaging)
38 | package(packaging, :id=>'other')
39 | end
40 | project('foo').packages.uniq.size.should eql(2)
41 | end
42 |
43 | it 'should complain if option not known' do
44 | packaging = @packaging
45 | define 'foo', :version=>'1.0' do
46 | lambda { package(packaging, :unknown_option=>true) }.should raise_error(ArgumentError, /no such option/)
47 | end
48 | end
49 |
50 | it 'should respond to with() and return self' do
51 | packaging = @packaging
52 | define 'foo', :version=>'1.0' do
53 | package(packaging).with({}).should be(package(packaging))
54 | end
55 | end
56 |
57 | it 'should respond to with() and complain if unknown option' do
58 | packaging = @packaging
59 | define 'foo', :version=>'1.0' do
60 | lambda { package(packaging).with(:unknown_option=>true) }.should raise_error(ArgumentError, /does not support the option/)
61 | end
62 | end
63 | end
64 |
--------------------------------------------------------------------------------
/spec/groovy/doc_spec.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 |
17 | require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18 |
19 | describe "Groovydoc" do
20 |
21 | it 'should pick :windowtitle from project name by default' do
22 | define 'foo' do
23 | doc.using :groovydoc
24 |
25 | define 'bar' do
26 | doc.using :groovydoc
27 | end
28 | end
29 |
30 | project('foo').doc.options[:windowtitle].should eql('foo')
31 | project('foo:bar').doc.options[:windowtitle].should eql('foo:bar')
32 | end
33 |
34 | it 'should pick :windowtitle from project description by default, if available' do
35 | desc 'My App'
36 | define 'foo' do
37 | doc.using :groovydoc
38 | end
39 | project('foo').doc.options[:windowtitle].should eql('My App')
40 | end
41 |
42 | it 'should not override explicit :windowtitle option' do
43 | define 'foo' do
44 | doc.using :groovydoc
45 | doc.using :windowtitle => 'explicit'
46 | end
47 | project('foo').doc.options[:windowtitle].should eql('explicit')
48 | end
49 |
50 | it 'should identify itself from groovy source directories' do
51 | write 'src/main/groovy/some/A.java', 'package some; public class A {}'
52 | write 'src/main/groovy/some/B.groovy', 'package some; public class B {}'
53 | define('foo') do
54 | doc.engine.should be_a(Buildr::Doc::Groovydoc)
55 | end
56 | end
57 |
58 | it 'should produce Groovydocs' do
59 | write 'src/main/groovy/some/A.java', 'package some; public class A {}'
60 | write 'src/main/groovy/some/B.groovy', 'package some; public class B {}'
61 | define('foo')
62 | project('foo').doc.invoke
63 | file('target/doc/index.html').should exist
64 | end
65 | end
66 |
--------------------------------------------------------------------------------
/addon/buildr/antlr.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr
17 | # Provides ANTLR grammar generation tasks. Require explicitly using require "buildr/antlr".
18 | module ANTLR
19 | REQUIRES = [ "org.antlr:antlr:jar:3.0", "antlr:antlr:jar:2.7.7", "org.antlr:stringtemplate:jar:3.0" ]
20 |
21 | Java.classpath << REQUIRES
22 |
23 | class << self
24 | def antlr(*args)
25 | options = Hash === args.last ? args.pop : {}
26 | rake_check_options options, :output, :token
27 |
28 | args = args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "/**/*.g"] : f }.flatten
29 | args = ["-o", options[:output]] + args if options[:output]
30 | if options[:token]
31 | # antlr expects the token directory to exist when it starts
32 | mkdir_p options[:token]
33 | args = ["-lib", options[:token]] + args
34 | end
35 | Java.load
36 | #Java.org.antlr.Tool.new_with_sig("[Ljava.lang.String;", args).process
37 | Java.org.antlr.Tool.new(args.to_java(Java.java.lang.String)).process
38 | end
39 | end
40 |
41 | def antlr(*args)
42 | if Hash === args.last
43 | options = args.pop
44 | in_package = options[:in_package].split(".")
45 | token = options[:token].split(".") if options[:token]
46 | else
47 | in_package = []; token = nil
48 | end
49 | file(path_to(:target, :generated, :antlr)=>args.flatten) do |task|
50 | args = {:output=>File.join(task.name, in_package)}
51 | args.merge!({:token=>File.join(task.name, token)}) if token
52 | ANTLR.antlr task.prerequisites, args
53 | end
54 | end
55 |
56 | end
57 |
58 | class Project
59 | include ANTLR
60 | end
61 | end
62 |
--------------------------------------------------------------------------------
/rakelib/rspec.rake:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | require 'rspec/core/rake_task'
17 | directory '_reports'
18 |
19 | def default_spec_opts
20 | default = %w{--order random:123 --format documentation --out _reports/specs.txt --backtrace}
21 | default << '--colour' if $stdout.isatty && !(RbConfig::CONFIG['host_os'] =~ /mswin|win32|dos/i)
22 | default
23 | end
24 |
25 | # RSpec doesn't support file exclusion, so hack our own.
26 | class RSpec::Core::RakeTask
27 | attr_accessor :rspec_files
28 | private
29 | def files_to_run
30 | @rspec_files
31 | end
32 | end
33 |
34 | desc 'Run all specs'
35 | RSpec::Core::RakeTask.new :spec => ['_reports', :compile] do |task|
36 | ENV['USE_FSC'] = 'no'
37 | files = FileList['spec/**/*_spec.rb']
38 | files = files.delete_if {|f| f =~ /^spec\/groovy\//} if RUBY_PLATFORM[/java/]
39 | task.rspec_files = files
40 | task.rspec_opts = %w{--order random:123 --format html --out _reports/specs.html --backtrace}
41 | end
42 | file('_reports/specs.html') { task(:spec).invoke }
43 |
44 | task :load_ci_reporter do
45 | gem 'ci_reporter'
46 | ENV['CI_REPORTS'] = '_reports/ci'
47 | # CI_Reporter does not quote the path to rspec_loader which causes problems when ruby is installed in C:/Program Files.
48 | # However, newer versions of rspec don't like double quotes escaping as well, so removing them for now.
49 | ci_rep_path = Gem.loaded_specs['ci_reporter'].full_gem_path
50 | ENV['SPEC_OPTS'] = [ENV['SPEC_OPTS'], default_spec_opts, '--require', "#{ci_rep_path}/lib/ci/reporter/rake/rspec_loader.rb", '--format', 'CI::Reporter::RSpec'].join(" ")
51 | end
52 |
53 | desc 'Run all specs with CI reporter'
54 | task 'ci' => %w(clobber load_ci_reporter spec)
55 |
56 | task 'clobber' do
57 | rm_f 'failed'
58 | rm_rf '_reports'
59 | rm_rf 'tmp'
60 | end
61 |
--------------------------------------------------------------------------------
/lib/buildr/core/osx.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | # Let's see if we can use Growl. Must be running from console in verbose mode.
17 | if $stdout.isatty && verbose
18 | def growl_notify(type, title, message)
19 | begin
20 | # Loading Ruby Cocoa can slow the build down (hooks on Object class), so we're
21 | # saving the best for last and only requiring it at the very end.
22 | require 'osx/cocoa'
23 | icon = OSX::NSApplication.sharedApplication.applicationIconImage
24 | icon = OSX::NSImage.alloc.initWithContentsOfFile(File.join(File.dirname(__FILE__), '../resources/buildr.icns'))
25 |
26 | # Register with Growl, that way you can turn notifications on/off from system preferences.
27 | OSX::NSDistributedNotificationCenter.defaultCenter.
28 | postNotificationName_object_userInfo_deliverImmediately(:GrowlApplicationRegistrationNotification, nil,
29 | { :ApplicationName=>'Buildr', :AllNotifications=>['Completed', 'Failed'],
30 | :ApplicationIcon=>icon.TIFFRepresentation }, true)
31 |
32 | OSX::NSDistributedNotificationCenter.defaultCenter.
33 | postNotificationName_object_userInfo_deliverImmediately(:GrowlNotification, nil,
34 | { :ApplicationName=>'Buildr', :NotificationName=>type,
35 | :NotificationTitle=>title, :NotificationDescription=>message }, true)
36 | rescue Exception
37 | # We get here in two cases: system doesn't have Growl installed so one of the OSX
38 | # calls raises an exception; system doesn't have osx/cocoa, e.g. MacPorts Ruby 1.9,
39 | # so we also need to rescue LoadError.
40 | end
41 | end
42 |
43 | Buildr.application.on_completion { |title, message| growl_notify('Completed', title, message) if verbose }
44 | Buildr.application.on_failure { |title, message, ex| growl_notify('Failed', title, message) if verbose }
45 | end
46 |
--------------------------------------------------------------------------------
/lib/buildr/packaging/gems.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | Gem.autoload :Package, 'rubygems/package'
17 |
18 | module Buildr #:nodoc:
19 |
20 | class PackageGemTask < ArchiveTask
21 |
22 | def initialize(*args)
23 | super
24 | @spec = Gem::Specification.new
25 | end
26 |
27 | def spec
28 | yield @spec if block_given?
29 | @spec
30 | end
31 |
32 | def upload
33 | end
34 |
35 | private
36 |
37 | def create_from(file_map)
38 | spec.mark_version
39 | spec.validate
40 |
41 | File.open(name, 'wb') do |io|
42 | Gem::Package.open(io, 'w', nil) do |pkg|
43 | pkg.metadata = spec.to_yaml
44 | file_map.each do |path, content|
45 | next if content.nil? || File.directory?(content.to_s)
46 | pkg.add_file_simple(path, File.stat(content.to_s).mode & 0777, File.size(content.to_s)) do |os|
47 | File.open(content.to_s, "rb") do |file|
48 | os.write file.read(4096) until file.eof?
49 | end
50 | end
51 | end
52 | end
53 | end
54 | end
55 | end
56 |
57 | module PackageAsGem #:nodoc:
58 |
59 | def package_as_gem(file_name) #:nodoc:
60 | PackageGemTask.define_task(file_name).tap do |gem|
61 | %w{ lib test doc }.each do |dir|
62 | gem.include :from=>_(dir), :path=>dir if File.directory?(_(dir))
63 | end
64 | gem.spec do |spec|
65 | spec.name = id
66 | spec.version = version.gsub('-','.') # RubyGems doesn't like '-' in version numbers
67 | spec.summary = full_comment
68 | spec.has_rdoc = true
69 | spec.rdoc_options << '--title' << comment
70 | spec.require_path = 'lib'
71 | end
72 | end
73 | end
74 | end
75 |
76 | class Project
77 | include PackageAsGem
78 | end
79 | end
80 |
--------------------------------------------------------------------------------
/addon/buildr/jaxb_xjc.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr
17 | module JaxbXjc
18 | class << self
19 |
20 | def jaxb_version
21 | "2.2.1"
22 | end
23 |
24 | # The specs for requirements
25 | def dependencies
26 | [
27 | "javax.xml.bind:jaxb-api:jar:#{jaxb_version}",
28 | "com.sun.xml.bind:jaxb-impl:jar:#{jaxb_version}",
29 | "com.sun.xml.bind:jaxb-xjc:jar:#{jaxb_version}"
30 | ]
31 | end
32 |
33 | # Repositories containing the requirements
34 | def remote_repository
35 | "http://download.java.net/maven/2"
36 | end
37 |
38 | def xjc(*args)
39 | cp = Buildr.artifacts(self.dependencies).each(&:invoke).map(&:to_s)
40 | Java::Commands.java 'com.sun.tools.xjc.XJCFacade', *(args + [{ :classpath => cp }])
41 | end
42 | end
43 |
44 | def compile_jaxb(files, *args)
45 | options = Hash === args.last ? args.pop.dup : {}
46 | rake_check_options options, :directory, :keep_content, :package, :id
47 | args = args.dup
48 | files = Array === files ? files.flatten : [files]
49 |
50 | target_dir = File.expand_path(options[:directory] || _(:target, :generated, :jaxb, 'main/java'))
51 | timestamp_file = File.expand_path("#{target_dir}/jaxb-#{options[:id] || 1}.cache")
52 |
53 | project.iml.main_source_directories << target_dir if project.iml?
54 |
55 | file(target_dir => timestamp_file)
56 |
57 | file(timestamp_file => files.flatten) do |task|
58 | rm_rf target_dir unless options[:keep_content]
59 | mkdir_p target_dir
60 | args << "-d" << target_dir
61 | args << "-p" << options[:package] if options[:package]
62 | args += files.collect{|f| f.to_s}
63 | JaxbXjc.xjc args
64 | touch timestamp_file
65 | end
66 |
67 | target_dir
68 | end
69 | end
70 | end
71 |
72 | class Buildr::Project
73 | include Buildr::JaxbXjc
74 | end
75 |
--------------------------------------------------------------------------------
/tests/integration_testing.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | TEST_DIR = File.dirname(File.expand_path(__FILE__))
17 | BUILDR = ENV['BUILDR'] || File.expand_path("#{TEST_DIR}/../_buildr")
18 |
19 | require 'test/unit'
20 | require 'zip/zip'
21 |
22 | module Buildr
23 | module IntegrationTests
24 |
25 | def self.test(folder, cmd, after_block = nil)
26 |
27 | eval <<-TEST
28 | class #{folder.sub("-", "").capitalize} < Test::Unit::TestCase
29 |
30 | def test_#{folder.sub("-", "")}
31 | begin
32 | result = `cd #{TEST_DIR}/#{folder} ; #{BUILDR} #{cmd}`
33 | assert($?.success?, 'Command success?')
34 | #{ after_block || "" }
35 | ensure
36 | %x[cd #{TEST_DIR}/#{folder} ; #{BUILDR} clean]
37 | end
38 |
39 | end
40 |
41 | end
42 | TEST
43 |
44 | end
45 |
46 | #BUILDR-320 still not resolved.
47 | #test "BUILDR-320", "--trace -P"
48 |
49 | test "JavaSystemProperty", "test"
50 |
51 | test "helloWorld", "package"
52 |
53 | test "compile_with_parent", "compile"
54 |
55 | test "junit3", "test"
56 |
57 | test "include_path", "package", <<-CHECK
58 | path = File.expand_path("#{TEST_DIR}/include_path/target/proj-1.0.zip")
59 | assert(File.exist?(path), "File exists?")
60 | Zip::ZipFile.open(path) {|zip|
61 | assert(!zip.get_entry("distrib/doc/index.html").nil?)
62 | assert(!zip.get_entry("distrib/lib/slf4j-api-1.6.1.jar").nil?)
63 | }
64 | CHECK
65 |
66 | test "include_as", "package", <<-CHECK
67 | path = File.expand_path("#{TEST_DIR}/include_as/target/proj-1.0.zip")
68 | assert(File.exist? path)
69 | Zip::ZipFile.open(path) {|zip|
70 | assert(!zip.get_entry("docu/index.html").nil?)
71 | assert(!zip.get_entry("lib/logging.jar").nil?)
72 | }
73 | CHECK
74 |
75 | test "package_war_as_jar", "package", <<-CHECK
76 | assert(File.exist? "#{TEST_DIR}/package_war_as_jar/target/webapp-1.0.jar")
77 | %x[cd #{TEST_DIR}/package_war_as_jar ; #{BUILDR} clean]
78 | assert($?.success?)
79 | CHECK
80 |
81 | end
82 | end
83 |
--------------------------------------------------------------------------------
/spec/groovy/bdd_spec.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
17 |
18 |
19 | describe Buildr::Groovy::EasyB do
20 |
21 | def foo(*args, &prc)
22 | define('foo', *args) do
23 | test.using :easyb
24 | if prc
25 | instance_eval(&prc)
26 | else
27 | self
28 | end
29 | end
30 | end
31 |
32 | it 'should apply to a project having EasyB sources' do
33 | define('one', :base_dir => 'one') do
34 | write _('src/spec/groovy/SomeSpecification.groovy'), 'true;'
35 | Buildr::Groovy::EasyB.applies_to?(self).should be_true
36 | end
37 | define('two', :base_dir => 'two') do
38 | write _('src/test/groovy/SomeSpecification.groovy'), 'true;'
39 | Buildr::Groovy::EasyB.applies_to?(self).should be_false
40 | end
41 | define('three', :base_dir => 'three') do
42 | write _('src/spec/groovy/SomeStory.groovy'), 'true;'
43 | Buildr::Groovy::EasyB.applies_to?(self).should be_true
44 | end
45 | define('four', :base_dir => 'four') do
46 | write _('src/test/groovy/SomeStory.groovy'), 'true;'
47 | Buildr::Groovy::EasyB.applies_to?(self).should be_false
48 | end
49 | end
50 |
51 | it 'should be selected by :easyb name' do
52 | foo { test.framework.should eql(:easyb) }
53 | end
54 |
55 | it 'should select a java compiler if java sources are found' do
56 | foo do
57 | write _('src/spec/java/SomeSpecification.java'), 'public class SomeSpecification {}'
58 | test.compile.language.should eql(:java)
59 | end
60 | end
61 |
62 | it 'should include src/spec/groovy/*Specification.groovy' do
63 | foo do
64 | spec = _('src/spec/groovy/SomeSpecification.groovy')
65 | write spec, 'true'
66 | test.invoke
67 | test.tests.should include(spec)
68 | end
69 | end
70 |
71 | it 'should include src/spec/groovy/*Story.groovy' do
72 | foo do
73 | spec = _('src/spec/groovy/SomeStory.groovy')
74 | write spec, 'true'
75 | test.invoke
76 | test.tests.should include(spec)
77 | end
78 | end
79 |
80 | end # EasyB
81 |
--------------------------------------------------------------------------------
/doc/scripts/install-linux.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with this
4 | # work for additional information regarding copyright ownership. The ASF
5 | # licenses this file to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 | # License for the specific language governing permissions and limitations under
15 | # the License.
16 | if [ -z `which ruby` ] ; then
17 | echo "You do not have Ruby 1.8.6 ..."
18 | # yum comes first since some people have apt-get installed in addition to yum.
19 | # urpmi is added in case of mandriva : apt-get or yum are working for mandriva too
20 | if [ `which yum` ] ; then
21 | echo "Installing Ruby using yum"
22 | sudo yum install ruby rubygems ruby-devel gcc
23 | elif [ `which apt-get` ] ; then
24 | echo "Installing Ruby using apt-get"
25 | # ruby package does not contain RDoc, IRB, etc; ruby-full is a meta-package.
26 | # build-essentials not installed by default in Ubuntu, required for C extensions.
27 | sudo apt-get install ruby-full ruby1.8-dev libopenssl-ruby build-essential
28 | # RubyGems broken on Ubuntu, installing directly from source.
29 | echo "Installing RubyGems from RubyForge"
30 | wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
31 | tar xzf rubygems-1.3.7.tgz
32 | cd rubygems-1.3.7
33 | sudo ruby setup.rb
34 | cd ..
35 | rm -rf rubygems-1.3.7
36 | # ruby is same as ruby1.8, we need gem that is same as gem1.8
37 | sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
38 | elif [ `which urpmi` ] ; then
39 | echo "Installing Ruby using urpmi"
40 | sudo urpmi ruby rubygems ruby-devel gcc
41 | if [ $? -ne 0 ] ; then
42 | echo "URPMI install error"
43 | exit 1
44 | fi
45 | else
46 | echo "Can only install Ruby 1.8.6 using apt-get, yum or urpmi, and can't find any of them"
47 | exit 1
48 | fi
49 | echo
50 | fi
51 |
52 | if [ -z $JAVA_HOME ] ; then
53 | echo "Please set JAVA_HOME before proceeding"
54 | exit 1
55 | fi
56 |
57 | if [ $(gem --version) \< '1.3.7' ] ; then
58 | echo "Upgrading to latest version of RubyGems"
59 | sudo gem update --system
60 | sudo update_rubygems
61 | echo
62 | fi
63 |
64 | if [ `which buildr` ] ; then
65 | echo "Updating to the latest version of Buildr"
66 | sudo env JAVA_HOME=$JAVA_HOME gem update buildr
67 | else
68 | echo "Installing the latest version of Buildr"
69 | sudo env JAVA_HOME=$JAVA_HOME gem install buildr
70 | fi
71 | echo
72 |
73 | buildr --version
74 |
--------------------------------------------------------------------------------
/spec/java/run_spec.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 |
17 | require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18 |
19 |
20 | describe Run::JavaRunner do
21 |
22 | it 'should fail on error' do
23 | define 'foo' do
24 | run.using :java, :main => 'org.example.NonExistentMain' # class doesn't exist
25 | end
26 | lambda { project('foo').run.invoke }.should raise_error(RuntimeError, /Failed to execute java/)
27 | end
28 |
29 | it 'should execute main class' do
30 | write 'src/main/java/org/example/Main.java', <<-JAVA
31 | package org.example;
32 | public class Main {
33 | public static void main(String[] args) {
34 | System.out.println("Hello, world!");
35 | }
36 | }
37 | JAVA
38 | define 'foo' do
39 | run.using :main => 'org.example.Main'
40 | end
41 | project('foo').run.prerequisites.should include(task("foo:compile"))
42 | end
43 |
44 | it 'should accept :main option as an array including parameters for the main class' do
45 | define 'foo' do
46 | run.using :java, :main => ['org.example.Main', '-t', 'input.txt']
47 | end
48 | Java::Commands.should_receive(:java).once.with do |*args|
49 | args[0].should == ['org.example.Main', '-t', 'input.txt']
50 | end
51 | project('foo').run.invoke
52 | end
53 |
54 | it 'should accept :java_args and pass them to java' do
55 | define 'foo' do
56 | run.using :java, :main => 'foo', :java_args => ['-server']
57 | end
58 | Java::Commands.should_receive(:java).once.with do |*args|
59 | args[0].should == 'foo'
60 | args[1][:java_args].should include('-server')
61 | end
62 | project('foo').run.invoke
63 | end
64 |
65 | it 'should accept :properties and pass them as -Dproperty=value to java' do
66 | define 'foo' do
67 | run.using :java, :main => 'foo', :properties => { :foo => 'one', :bar => 'two' }
68 | end
69 | Java::Commands.should_receive(:java).once.with do |*args|
70 | args[0].should == 'foo'
71 | args[1][:properties][:foo].should == 'one'
72 | args[1][:properties][:bar].should == 'two'
73 | end
74 | project('foo').run.invoke
75 | end
76 |
77 | end
78 |
--------------------------------------------------------------------------------
/addon/buildr/package_as_nsis.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr
17 | module PackageAsNsis
18 | include Extension
19 |
20 | class NSISTask < Rake::FileTask
21 | attr_accessor :nsi
22 | attr_accessor :values
23 | attr_accessor :nsis_executable
24 | attr_accessor :nsis_major_version
25 |
26 | def initialize(*args) #:nodoc:
27 | self.nsis_executable = "makensis"
28 | self.nsis_major_version = 3
29 | self.values = {}
30 |
31 | super(*args)
32 |
33 | enhance do
34 | info "Calling makensis"
35 | # We make available one variable to the nsi script:
36 | # Use it like this: OutFile "${OUTPUT}"
37 | values = self.values.merge("OUTPUT" => to_s)
38 |
39 | log_level_param = (self.nsis_major_version == 2 ? "/" : "-") + (verbose ? "V2" : "V0")
40 | define_prefix = (self.nsis_major_version == 2) ? "/D" : "-D"
41 |
42 | command = "#{self.nsis_executable} #{log_level_param} #{values.inject([]) { |array, (key, value)| array << "#{define_prefix}#{key}=#{value}"; array }.join(" ")} #{self.nsi}"
43 | trace command
44 | system(command) or fail "Error while executing makeNSIS"
45 | end
46 | end
47 |
48 | # :call-seq:
49 | # with(options) => self
50 | #
51 | # Passes options to the task and returns self. Some tasks support additional options, for example,
52 | # the WarTask supports options like :manifest, :libs and :classes.
53 | #
54 | # For example:
55 | # package(:jar).with(:manifest=>'MANIFEST_MF')
56 | def with(options)
57 | options.each do |key, value|
58 | begin
59 | send "#{key}=", value
60 | rescue NoMethodError
61 | raise ArgumentError, "#{self.class.name} does not support the option #{key}"
62 | end
63 | end
64 | self
65 | end
66 | end
67 |
68 | def package_as_nsis(file_name)
69 | NSISTask.define_task(file_name)
70 | end
71 |
72 | def package_as_nsis_spec(spec)
73 | spec.merge(:type=>:exe)
74 | end
75 | end
76 | end
77 |
78 | class Buildr::Project
79 | include Buildr::PackageAsNsis
80 | end
81 |
--------------------------------------------------------------------------------
/addon/buildr/protobuf.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr
17 |
18 | # Provides Protocol buffer code generation tasks.
19 | #
20 | # Require explicitly using require "buildr/protobuf".
21 | #
22 | # Usage in your project:
23 | #
24 | # protoc _("path/to/proto/files")
25 | #
26 | # and also supports two options,
27 | #
28 | # :output => "target/generated/protoc" # this is the default
29 | # :lang => "java" # defaults to compile.language
30 | #
31 | module Protobuf
32 | class << self
33 | def protoc(*args)
34 | options = Hash === args.last ? args.pop : {}
35 | rake_check_options options, :output, :lang, :include
36 |
37 | options[:lang] ||= :java
38 | options[:output] ||= File.expand_path "target/generated/protoc"
39 | options[:include] ||= []
40 |
41 | command_line = []
42 |
43 | command_line << "--#{options[:lang]}_out=#{options[:output]}" if options[:output]
44 |
45 | (paths_from_sources(*args) + options[:include]).each { |i| command_line << "-I#{i}" }
46 |
47 | command_line += files_from_sources(*args)
48 |
49 | mkdir_p( options[:output] )
50 |
51 | system protoc_path, *command_line
52 | end
53 |
54 | def protoc_path
55 | ENV['PROTOC'] || "protoc"
56 | end
57 |
58 | def files_from_sources(*args)
59 | args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "/**/*.proto"] : f }.flatten
60 | end
61 |
62 | def paths_from_sources(*args)
63 | args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? f : File.dirname(f) }
64 | end
65 | end
66 |
67 | def protoc(*args)
68 | if Hash === args.last
69 | options = args.pop
70 | else
71 | options = {}
72 | end
73 |
74 | options[:output] ||= path_to(:target, :generated, :protoc)
75 | options[:lang] ||= compile.language if compile.language
76 |
77 | file(options[:output]=>Protobuf.files_from_sources(*args)) do |task|
78 | Protobuf.protoc task.prerequisites, options
79 | end
80 | end
81 |
82 | end
83 |
84 | class Project
85 | include Protobuf
86 | end
87 | end
88 |
--------------------------------------------------------------------------------
/lib/buildr/core/assets.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr #:nodoc:
17 |
18 | module Assets #:nodoc:
19 |
20 | # The base assets task that is responsible for
21 | # collecting all of the assets into a single output
22 | # directory
23 | class AssetsTask < Rake::FileTask
24 | attr_reader :project
25 |
26 | def project=(project)
27 | @project = project
28 | end
29 |
30 | # The list of input paths to add to output directory
31 | def paths
32 | unless @paths
33 | @paths = []
34 | @paths << project._(:source, :main, :assets) if File.exist?(project._(:source, :main, :assets))
35 | end
36 | @paths
37 | end
38 |
39 | protected
40 |
41 | def initialize(*args) #:nodoc:
42 | super
43 | enhance do
44 | paths = self.paths.flatten.compact
45 | if paths.size > 0
46 | mkdir_p name
47 | paths.collect do |a|
48 | a.is_a?(String) ? project.file(a) : a
49 | end.each do |a|
50 | a.invoke if a.respond_to?(:invoke)
51 | end.each do |asset|
52 | cp_r Dir["#{asset}/*"], "#{name}/"
53 | end
54 | end
55 | end
56 | end
57 |
58 | private
59 |
60 | def out_of_date?(stamp)
61 | super ||
62 | self.paths.any? { |n| n.respond_to?(:needed?) && n.needed? }
63 | end
64 |
65 | end
66 |
67 | module ProjectExtension
68 | include Extension
69 |
70 | first_time do
71 | desc "Prepare the assets"
72 | Project.local_task("assets")
73 | end
74 |
75 | before_define do |project|
76 | # Force the construction of the assets task
77 | project.assets.paths
78 | end
79 |
80 | # Access the asset task
81 | def assets
82 | if @assets.nil?
83 | @assets = AssetsTask.define_task(project._(:target, :main, :assets) => [])
84 | @assets.project = self
85 | project.task('assets').enhance([@assets])
86 | project.build.enhance([@assets])
87 | end
88 | @assets
89 | end
90 | end
91 | end
92 | end
93 |
94 | class Buildr::Project #:nodoc:
95 | include ::Buildr::Assets::ProjectExtension
96 | end
97 |
--------------------------------------------------------------------------------
/addon/buildr/single_intermediate_layout.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr #nodoc
17 | class Project #nodoc
18 | class << self
19 |
20 | alias :original_define :define
21 |
22 | # Monkey patch the built-in define so that there is a single root directory for
23 | # all of the generated artifacts within a project hierarchy.
24 | #
25 | def define(name, properties = nil, &block) #:yields:project
26 |
27 | properties = properties.nil? ? {} : properties.dup
28 |
29 | parent_name = name.split(':')[0...-1]
30 | parent = parent_name.empty? ? nil : Buildr.application.lookup(parent_name.join(':'))
31 |
32 | # Follow the same algorithm as in project code
33 | if properties[:base_dir]
34 | base_dir = properties[:base_dir]
35 | elsif parent
36 | base_dir = File.expand_path(name.split(':').last, parent.base_dir)
37 | else
38 | base_dir = Dir.pwd
39 | end
40 |
41 | # The top directory is the base directory of the root project
42 | top_dir = base_dir
43 | while parent
44 | top_dir = parent.base_dir
45 | parent = parent.parent
46 | end
47 |
48 | target_dir = "#{top_dir}/target/#{name.gsub(':', '_')}"
49 | reports_dir = "#{top_dir}/reports/#{name.gsub(':', '_')}"
50 | target_dir = ::Buildr::Util.relative_path(target_dir, File.expand_path(base_dir))
51 | reports_dir = ::Buildr::Util.relative_path(reports_dir, File.expand_path(base_dir))
52 |
53 | properties[:layout] = Buildr::Layout::Default.new unless properties[:layout]
54 | properties[:layout][:target] = target_dir
55 | properties[:layout][:reports] = reports_dir
56 | properties[:layout][:target, :main] = target_dir
57 |
58 | Project.original_define(name, properties) do
59 | project.instance_eval &block
60 | if top_dir == base_dir && project.iml?
61 | project.iml.excluded_directories << "#{base_dir}/target"
62 | project.iml.excluded_directories << "#{base_dir}/reports"
63 | clean { rm_rf "#{base_dir}/target" }
64 | clean { rm_rf "#{base_dir}/reports" }
65 | end
66 | project
67 | end
68 | end
69 | end
70 | end
71 | end
72 |
--------------------------------------------------------------------------------
/lib/buildr/groovy/doc.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr #:nodoc:
17 | module Doc #:nodoc:
18 |
19 | module GroovydocDefaults #:nodoc:
20 | include Extension
21 |
22 | # Default groovydoc -doc-title to project's comment or name
23 | after_define(:groovydoc => :doc) do |project|
24 | if project.doc.engine? Groovydoc
25 | options = project.doc.options
26 | options[:windowtitle] = (project.comment || project.name) unless options[:windowtitle]
27 | end
28 | end
29 | end
30 |
31 | class Groovydoc < Base
32 | specify :language => :groovy, :source_ext => ['java', 'groovy']
33 |
34 | def generate(sources, target, options = {})
35 | mkdir_p target
36 | cmd_args = [ '-d', target, trace?(:groovydoc) ? '-verbose' : nil ].compact
37 | options.reject { |key, value| [:sourcepath, :classpath].include?(key) }.
38 | each { |key, value| value.invoke if value.respond_to?(:invoke) }.
39 | each do |key, value|
40 | case value
41 | when true, nil
42 | cmd_args << "-#{key}"
43 | when false
44 | cmd_args << "-no#{key}"
45 | when Hash
46 | value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
47 | else
48 | cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
49 | end
50 | end
51 | [:sourcepath, :classpath].each do |option|
52 | Array(options[option]).flatten.tap do |paths|
53 | cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
54 | end
55 | end
56 | cmd_args += sources.flatten.uniq
57 | unless Buildr.application.options.dryrun
58 | info "Generating Groovydoc for #{project.name}"
59 | trace (['groovydoc'] + cmd_args).join(' ')
60 | result = Java::Commands.java('org.codehaus.groovy.tools.groovydoc.Main', cmd_args,
61 | :classpath => Buildr::Groovy.dependencies)
62 | end
63 | end
64 | end
65 | end
66 |
67 | class Project #:nodoc:
68 | include GroovydocDefaults
69 | end
70 | end
71 |
72 | Buildr::Doc.engines << Buildr::Doc::Groovydoc
73 |
--------------------------------------------------------------------------------
/doc/css/print.css:
--------------------------------------------------------------------------------
1 | /* Licensed to the Apache Software Foundation (ASF) under one or more
2 | * contributor license agreements. See the NOTICE file distributed with this
3 | * work for additional information regarding copyright ownership. The ASF
4 | * licenses this file to you under the Apache License, Version 2.0 (the
5 | * "License"); you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 |
18 | @media print {
19 | @page { size: letter; }
20 | @page:first {
21 | @top-left { content: normal }
22 | @top-right { content: normal }
23 | }
24 | @page:right {
25 | margin: 1.25in 1in 1.5in 1.5in;
26 | font: normal 10pt "Gill Sans" !important;
27 | @top-left { content: string(pagetitle); }
28 | @top-right { content: counter(page); }
29 | }
30 | @page:left {
31 | margin: 1.25in 1.5in 1.5in 1in;
32 | font: normal 10pt "Gill Sans" !important;
33 | @top-left { content: counter(page); }
34 | @top-right { content: string(pagetitle); }
35 | }
36 |
37 | title { string-set: doctitle content(); }
38 |
39 | body {
40 | font-family: "Palatino";
41 | margin: 0;
42 | color: black;
43 | background: white;
44 | font-size: 11pt;
45 | }
46 |
47 | h1 {
48 | string-set: pagetitle content();
49 | page-break-before: always;
50 | }
51 | h1:first-child { page-break-before: avoid; }
52 | h1, h2, h3 {
53 | font-family: "Gill Sans";
54 | }
55 | pre, p, blockquote { page-break-inside: avoid; }
56 | pre, code {
57 | font-family: "Monaco", "DejaVu Sans Mono", "Courier New", "Courier";
58 | font-size: 9pt;
59 | }
60 | pre br {
61 | display: none;
62 | }
63 | a:link, a:visited {
64 | background: transparent;
65 | text-decoration: none;
66 | }
67 |
68 |
69 | #header, #pages, #footer { display: none }
70 | #wrap, #content {
71 | float: none !important;
72 | color: black;
73 | background: transparent;
74 | width: auto !important;
75 | margin: 0;
76 | padding: 0;
77 | border: 0;
78 | }
79 |
80 | ol.toc a:link, ol.toc a:visited { text-decoration: none; }
81 | ol.toc a:after { content: leader('.') target-counter(attr(href), page); }
82 |
83 | .title {
84 | page-break-before: always;
85 | border: none;
86 | }
87 | .title img {
88 | display: block;
89 | width: 80%;
90 | margin: 2em auto 4em auto;
91 | }
92 | p.preface {
93 | page-break-before: always;
94 | padding-top: 1.5in;
95 | }
96 | div.preface.quotes {
97 | page-break-before: always;
98 | padding-top: 1in;
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/lib/buildr/java/ecj.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr #:nodoc:
17 | module Compiler #:nodoc:
18 |
19 | class Ecj < Javac
20 |
21 | OPTIONS = Buildr::Compiler::Javac::OPTIONS
22 |
23 | specify :language=>:java, :sources => 'java', :source_ext => 'java',
24 | :target=>'classes', :target_ext=>'class', :packaging=>:jar
25 |
26 | def compile(sources, target, dependencies) #:nodoc:
27 | check_options options, OPTIONS
28 | cmd_args = []
29 | # tools.jar contains the Java compiler.
30 | dependencies << Java.tools_jar if Java.tools_jar
31 | cmd_args << '-classpath' << ('"' + dependencies.join(File::PATH_SEPARATOR) + '"') unless dependencies.empty?
32 | source_paths = sources.select { |source| File.directory?(source) }
33 | cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
34 | cmd_args << '-d' << File.expand_path(target)
35 | cmd_args += ecj_args
36 | cmd_args += files_from_sources(sources)
37 | unless Buildr.application.options.dryrun
38 | trace((%w[javac -classpath org.eclipse.jdt.internal.compiler.batch.Main] + cmd_args).join(' '))
39 | Java.load
40 | Java.org.eclipse.jdt.internal.compiler.batch.Main.compile(cmd_args.join(" ")) or
41 | fail 'Failed to compile, see errors above'
42 | end
43 | end
44 |
45 | private
46 |
47 | # See arg list here: http://publib.boulder.ibm.com/infocenter/rsahelp/v7r0m0/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_api_compile.htm
48 | def ecj_args #:nodoc:
49 | args = []
50 | args << '-warn:none' unless options[:warnings]
51 | args << '-verbose' if trace?(:ecj)
52 | args << '-g' if options[:debug]
53 | args << '-deprecation' if options[:deprecation]
54 | args << '-source' << options[:source].to_s if options[:source]
55 | args << '-target' << options[:target].to_s if options[:target]
56 | case options[:lint]
57 | when Array then args << "-Xlint:#{options[:lint].join(',')}"
58 | when String then args << "-Xlint:#{options[:lint]}"
59 | when true then args << '-Xlint'
60 | end
61 | args + Array(options[:other])
62 | end
63 | end
64 | end
65 | end
66 |
67 | Java.classpath << "org.eclipse.jdt.core.compiler:ecj:jar:3.5.1"
68 | # Adding ecj before javac
69 | Buildr::Compiler.compilers.unshift Buildr::Compiler::Ecj
70 |
--------------------------------------------------------------------------------
/addon/buildr/gpg.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr
17 |
18 | # Signs the packages using gpg and uploads signatures as part of the upload process.
19 | #
20 | # Require explicitly using require "buildr/apg". This will result in all
21 | # packages being signed. The user must specify the GPG_USER environment key to identify
22 | # the key to use and may specify GPG_PASS if the key needs a password to access. e.g.
23 | #
24 | # $ GPG_USER=user@example.com GPG_PASSWD=secret buildr clean upload
25 | #
26 | module GPG
27 | class << self
28 |
29 | def sign_task(pkg)
30 | raise "ENV['GPG_USER'] not specified" unless ENV['GPG_USER']
31 | asc_filename = pkg.to_s + '.asc'
32 | return if file(asc_filename).prerequisites.include?(pkg.to_s)
33 | file(asc_filename => [pkg.to_s]) do
34 | info "GPG signing #{pkg.to_spec}"
35 |
36 | cmd = []
37 | cmd << 'gpg'
38 | cmd << '--local-user'
39 | cmd << ENV['GPG_USER']
40 | cmd << '--armor'
41 | cmd << '--output'
42 | cmd << pkg.to_s + '.asc'
43 | if ENV['GPG_PASS']
44 | cmd << '--passphrase'
45 | cmd << ENV['GPG_PASS']
46 | end
47 | cmd << '--detach-sig'
48 | cmd << '--batch'
49 | cmd << '--yes'
50 | cmd << pkg
51 | trace(cmd.join(' '))
52 | `#{cmd.join(' ')}`
53 | raise "Unable to generate signature for #{pkg}" unless File.exist?(asc_filename)
54 | end
55 | end
56 |
57 | def sign_and_upload(project, pkg)
58 | project.task(:upload).enhance do
59 | artifact = Buildr.artifact(pkg.to_spec_hash.merge(:type => "#{pkg.type}.asc"))
60 | artifact.from(sign_task(pkg))
61 | artifact.invoke
62 | artifact.upload
63 | end
64 | end
65 |
66 | def sign_and_upload_all_packages(project)
67 | project.packages.each { |pkg| Buildr::GPG.sign_and_upload(project, pkg) }
68 | project.packages.select {|pkg| pkg.respond_to?(:pom) }.map { |pkg| pkg.pom }.compact.uniq.each { |pom| Buildr::GPG.sign_and_upload(project, pom) }
69 | end
70 | end
71 |
72 | module ProjectExtension
73 | include Extension
74 |
75 | after_define do |project|
76 | Buildr::GPG.sign_and_upload_all_packages(project)
77 | end
78 | end
79 | end
80 | end
81 |
82 | class Buildr::Project
83 | include Buildr::GPG::ProjectExtension
84 | end
85 |
--------------------------------------------------------------------------------
/addon/buildr/javacc.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr
17 | # Provides JavaCC compile tasks. Require explicitly using require "buildr/javacc".
18 | module JavaCC
19 |
20 | REQUIRES = [ "net.java.dev.javacc:javacc:jar:4.0", "net.java.dev.javacc:javacc:jar:4.0" ]
21 |
22 | Java.classpath << REQUIRES
23 |
24 | class << self
25 |
26 | def javacc(*args)
27 | options = Hash === args.last ? args.pop : {}
28 | rake_check_options options, :output
29 |
30 | args = args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "/**/*.jj"] : f }.flatten
31 | args.unshift "-OUTPUT_DIRECTORY=#{options[:output]}" if options[:output]
32 | Java.load
33 | Java.org.javacc.parser.Main.mainProgram(args.to_java(Java.java.lang.String)) == 0 or
34 | fail "Failed to run JavaCC, see errors above."
35 | end
36 |
37 | def jjtree(*args)
38 | options = Hash === args.last ? args.pop : {}
39 | rake_check_options options, :output, :build_node_files
40 |
41 | args = args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "**/*.jjt"] : f }.flatten
42 | args.unshift "-OUTPUT_DIRECTORY=#{options[:output]}" if options[:output]
43 | args.unshift "-BUILD_NODE_FILES=#{options[:build_node_files] || false}"
44 | Java.load
45 | Java.org.javacc.jjtree.JJTree.new.main(args.to_java(Java.java.lang.String)) == 0 or
46 | fail "Failed to run JJTree, see errors above."
47 | end
48 |
49 | end
50 |
51 | def javacc(*args)
52 | if Hash === args.last
53 | options = args.pop
54 | in_package = options[:in_package].split(".")
55 | else
56 | in_package = []
57 | end
58 | file(path_to(:target, :generated, :javacc)=>args.flatten) do |task|
59 | JavaCC.javacc task.prerequisites, :output=>File.join(task.name, in_package)
60 | end
61 | end
62 |
63 | def jjtree(*args)
64 | if Hash === args.last
65 | options = args.pop
66 | in_package = options[:in_package].split(".")
67 | build_node_files = options[:build_node_files]
68 | else
69 | in_package = []
70 | end
71 | file(path_to(:target, :generated, :jjtree)=>args.flatten) do |task|
72 | JavaCC.jjtree task.prerequisites, :output=>File.join(task.name, in_package), :build_node_files=>build_node_files
73 | end
74 | end
75 |
76 | end
77 |
78 | class Project
79 | include JavaCC
80 | end
81 | end
82 |
--------------------------------------------------------------------------------
/addon/buildr/scss_lint-report.xsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
21 |
22 |
23 |
24 |
25 |
26 | ScssLint Violations
27 |
28 |
29 |
30 | Coding Style Check Results
31 |
32 |
33 |
34 | |
35 | Summary
36 | |
37 |
38 |
39 | | Files with errors |
40 |
41 |
42 | |
43 |
44 |
45 | | Total errors |
46 |
47 |
48 | |
49 |
50 |
51 |
52 | The following are violations of the ScssLint Rules:
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | | File: |
63 |
64 |
65 | |
66 |
67 |
68 |
69 |
70 | | Line |
71 | Column |
72 | Severity |
73 | Reason |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 | |
83 |
84 | |
85 |
86 |
87 | |
88 |
89 |
90 | |
91 |
92 |
93 | |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/lib/buildr/java/external.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr #:nodoc:
17 | module Compiler #:nodoc:
18 | class ExternalJavac< Buildr::Compiler::Javac
19 |
20 | OPTIONS = [:jvm, :warnings, :debug, :deprecation, :source, :target, :lint, :other]
21 |
22 | specify :language=>:java, :sources => 'java', :source_ext => 'java',
23 | :target=>'classes', :target_ext=>'class', :packaging=>:jar
24 |
25 |
26 | def compile(sources, target, dependencies) #:nodoc:
27 | check_options options, OPTIONS
28 | cmd_args = []
29 | # tools.jar contains the Java compiler.
30 | dependencies << Java.tools_jar if Java.tools_jar
31 | cmd_args << '-classpath' << dependencies.join(File::PATH_SEPARATOR) unless dependencies.empty?
32 | source_paths = sources.select { |source| File.directory?(source) }
33 | cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
34 | cmd_args << '-d' << File.expand_path(target)
35 | cmd_args += externaljavac_args
36 | Tempfile.open("external") {|tmp|
37 | tmp.write files_from_sources(sources).join(' ')
38 | cmd_args << "@#{tmp.path}"
39 | }
40 | unless Buildr.application.options.dryrun
41 | javac_path = File.join(options[:jvm] || ENV['JAVA_HOME'], "bin", "javac")
42 | final_args = cmd_args.insert(0, javac_path).push('2>&1').join(' ')
43 | trace(final_args)
44 | info %x[#{final_args}]
45 | fail 'Failed to compile, see errors above' unless $?.success?
46 | end
47 | end
48 |
49 | private
50 |
51 | # See arg list here: http://publib.boulder.ibm.com/infocenter/rsahelp/v7r0m0/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_api_compile.htm
52 | def externaljavac_args #:nodoc:
53 | args = []
54 | args << '-nowarn' unless options[:warnings]
55 | args << '-verbose' if trace?(:javac)
56 | args << '-g' if options[:debug]
57 | args << '-deprecation' if options[:deprecation]
58 | args << '-source' << options[:source].to_s if options[:source]
59 | args << '-target' << options[:target].to_s if options[:target]
60 | case options[:lint]
61 | when Array then args << "-Xlint:#{options[:lint].join(',')}"
62 | when String then args << "-Xlint:#{options[:lint]}"
63 | when true then args << '-Xlint'
64 | end
65 | args + Array(options[:other])
66 | end
67 |
68 | end
69 |
70 | end
71 | end
72 |
73 | Buildr::Compiler.compilers << Buildr::Compiler::ExternalJavac
74 |
--------------------------------------------------------------------------------
/lib/buildr/java/test_result.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | # It is necessary to require these files here as the bdd plugin directly includes this file
17 | require 'yaml'
18 | require 'rspec/core/formatters/base_formatter'
19 |
20 | module Buildr #:nodoc:
21 | module TestFramework #:nodoc:
22 |
23 | # A class used by buildr for jruby based frameworks, so that buildr can know
24 | # which tests succeeded/failed.
25 | class TestResult
26 |
27 | class Error < ::Exception
28 | attr_reader :message, :backtrace
29 | def initialize(message, backtrace)
30 | @message = message
31 | @backtrace = backtrace
32 | set_backtrace backtrace
33 | end
34 |
35 | def self.dump_yaml(file, e)
36 | FileUtils.mkdir_p File.dirname(file)
37 | File.open(file, 'w') { |f| f.puts(YAML.dump(Error.new(e.message, e.backtrace))) }
38 | end
39 |
40 | def self.guard(file)
41 | begin
42 | yield
43 | rescue => e
44 | dump_yaml(file, e)
45 | end
46 | end
47 | end
48 |
49 | attr_accessor :failed, :succeeded
50 |
51 | def initialize
52 | @failed, @succeeded = [], []
53 | end
54 |
55 | # An Rspec formatter used by buildr
56 | class YamlFormatter < ::RSpec::Core::Formatters::BaseFormatter
57 | attr_reader :result
58 |
59 | def initialize(output)
60 | super(output)
61 | @result = Hash.new
62 | @result[:succeeded] = []
63 | @result[:failed] = []
64 | end
65 |
66 | def example_passed(example)
67 | super(example)
68 | result.succeeded << example_name(example)
69 | end
70 |
71 | def example_pending(example)
72 | super(example)
73 | result.succeeded << example_name(example)
74 | end
75 |
76 | def example_failed(example)
77 | super(example)
78 | result.failed << example_name(example)
79 | end
80 |
81 | def start(example_count)
82 | super(example_count)
83 | @result = TestResult.new
84 | end
85 |
86 | def close
87 | super
88 | result.succeeded = result.succeeded - result.failed
89 | output.puts YAML.dump(result)
90 | end
91 |
92 | private
93 | def example_name(example)
94 | example.file_path
95 | end
96 | end # YamlFormatter
97 |
98 | end # TestResult
99 | end
100 | end
101 |
--------------------------------------------------------------------------------
/lib/buildr/java/ant.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 |
17 | gem 'atoulme-Antwrap'
18 | autoload :Antwrap, 'antwrap'
19 | autoload :Logger, 'logger'
20 |
21 | module Buildr #:nodoc:
22 | module Ant
23 |
24 | # Which version of Ant we're using by default.
25 | VERSION = '1.8.3'
26 |
27 | class << self
28 | # Current version of Ant being used.
29 | def version
30 | Buildr.settings.build['ant'] || VERSION
31 | end
32 |
33 | # Ant classpath dependencies.
34 | def dependencies
35 | # Ant-Trax required for running the JUnitReport task, and there's no other place
36 | # to put it but the root classpath.
37 | @dependencies ||= ["org.apache.ant:ant:jar:#{version}", "org.apache.ant:ant-launcher:jar:#{version}"]
38 | end
39 |
40 | private
41 | def const_missing(const)
42 | return super unless const == :REQUIRES # TODO: remove in 1.5
43 | Buildr.application.deprecated "Please use Ant.dependencies/.version instead of Ant::REQUIRES/VERSION"
44 | dependencies
45 | end
46 | end
47 |
48 |
49 | Java.classpath << lambda { Ant.dependencies }
50 |
51 | # :call-seq:
52 | # ant(name) { |AntProject| ... } => AntProject
53 | #
54 | # Creates a new AntProject with the specified name, yield to the block for defining various
55 | # Ant tasks, and executes each task as it's defined.
56 | #
57 | # For example:
58 | # ant("hibernatedoclet') do |doclet|
59 | # doclet.taskdef :name=>'hibernatedoclet',
60 | # :classname=>'xdoclet.modules.hibernate.HibernateDocletTask', :classpath=>DOCLET
61 | # doclet.hibernatedoclet :destdir=>dest_dir, :force=>'true' do
62 | # hibernate :version=>'3.0'
63 | # fileset :dir=>source, :includes=>'**/*.java'
64 | # end
65 | # end
66 | def ant(name, &block)
67 | options = { :name=>name, :basedir=>Dir.pwd, :declarative=>true }
68 | options.merge!(:logger=> Logger.new(STDOUT), :loglevel=> Logger::DEBUG) if trace?(:ant)
69 | Java.load
70 | Antwrap::AntProject.new(options).tap do |project|
71 | # Set Ant logging level to debug (--trace), info (default) or error only (--quiet).
72 | project.project.getBuildListeners().get(0).
73 | setMessageOutputLevel((trace?(:ant) && 4) || (verbose && 2) || 0)
74 | yield project if block_given?
75 | end
76 | end
77 |
78 | end
79 |
80 | include Ant
81 | class Project
82 | include Ant
83 | end
84 |
85 | Buildr.help do
86 | Java.load
87 | "\nUsing Java #{ENV_JAVA['java.version']}, Ant #{Ant.version}."
88 | end
89 |
90 | end
91 |
--------------------------------------------------------------------------------
/addon/buildr/jibx.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | require 'java/java'
17 |
18 | module Buildr
19 |
20 | # Provides JiBX bytecode enhancement. Require explicitly using require 'buildr/jibx'.
21 | module JiBX
22 |
23 | JIBX_VERSION = '1.1.5'
24 | BCEL_VERSION = '5.2'
25 | STAX_VERSION = '1.0-2'
26 | XPP3_VERSION = '1.1.4c'
27 |
28 | REQUIRES = ["org.jibx:jibx-bind:jar:#{JIBX_VERSION}",
29 | "org.jibx:jibx-run:jar:#{JIBX_VERSION}",
30 | "org.apache.bcel:bcel:jar:#{BCEL_VERSION}",
31 | "javax.xml.stream:stax-api:jar:#{STAX_VERSION}",
32 | "xpp3:xpp3:jar:#{XPP3_VERSION}"]
33 |
34 | Java.classpath << REQUIRES
35 |
36 | class << self
37 |
38 | def bind(options)
39 | rake_check_options options, :classpath, :output, :binding, :target, :verbose, :load
40 | artifacts = Buildr.artifacts(options[:classpath]).each { |a| a.invoke }.map(&:to_s) + [options[:output].to_s]
41 | binding = file(options[:binding]).tap { |task| task.invoke }.to_s
42 |
43 | Buildr.ant 'jibx' do |ant|
44 | ant.taskdef :name=>'bind',
45 | :classname=>'org.jibx.binding.ant.CompileTask',
46 | :classpath => requires.join(File::PATH_SEPARATOR)
47 | ant.bind :verbose => options[:verbose].to_s, :load => options[:load].to_s, :binding=>options[:binding].to_s do
48 | ant.classpath :path => artifacts.join(File::PATH_SEPARATOR)
49 | end
50 | end
51 | end
52 |
53 | private
54 |
55 | def requires()
56 | @requires ||= Buildr.artifacts(REQUIRES).each { |artifact| artifact.invoke }.map(&:to_s)
57 | end
58 |
59 | end
60 |
61 | def jibx_bind(options = nil)
62 |
63 | # FIXME - add support for :bindingfileset and :classpathset
64 | # Note: either :binding or :bindingfileset should be set, and either
65 | # :classpath or :classpathset should be set, and options passed to
66 | # ant.bind should be adjusted accordingly. At present, only :binding
67 | # and :classpath are supported (which should be fine for most!)
68 | jibx_options = {:output => compile.target,
69 | :classpath => compile.classpath,
70 | :binding => path_to(:source, :main, :resources, 'META-INF/binding.xml'),
71 | :target => compile.target,
72 | :load => false,
73 | :verbose => false
74 | }
75 |
76 | JiBX.bind jibx_options.merge(options || {})
77 | end
78 |
79 | end
80 |
81 | class Project
82 | include JiBX
83 | end
84 | end
85 |
--------------------------------------------------------------------------------
/lib/buildr/java/doc.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr #:nodoc:
17 | module Doc #:nodoc:
18 |
19 | module JavadocDefaults
20 | include Extension
21 |
22 | # Default javadoc -windowtitle to project's comment or name
23 | after_define(:javadoc => :doc) do |project|
24 | if project.doc.engine? Javadoc
25 | options = project.doc.options
26 | options[:windowtitle] = (project.comment || project.name) unless options[:windowtitle]
27 | end
28 | end
29 | end
30 |
31 | # A convenient task for creating Javadocs from the project's compile task. Minimizes all
32 | # the hard work to calling #from and #using.
33 | #
34 | # For example:
35 | # doc.from(projects('myapp:foo', 'myapp:bar')).using(:windowtitle=>'My App')
36 | # Or, short and sweet:
37 | # desc 'My App'
38 | # define 'myapp' do
39 | # . . .
40 | # doc projects('myapp:foo', 'myapp:bar')
41 | # end
42 | class Javadoc < Base
43 |
44 | specify :language => :java, :source_ext => 'java'
45 |
46 | def generate(sources, target, options = {})
47 | cmd_args = [ '-d', target, trace?(:javadoc) ? '-verbose' : '-quiet' ]
48 | options.reject { |key, value| [:sourcepath, :classpath].include?(key) }.
49 | each { |key, value| value.invoke if value.respond_to?(:invoke) }.
50 | each do |key, value|
51 | case value
52 | when true, nil
53 | cmd_args << "-#{key}"
54 | when false
55 | cmd_args << "-no#{key}"
56 | when Hash
57 | value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
58 | else
59 | cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
60 | end
61 | end
62 | [:sourcepath, :classpath].each do |option|
63 | Array(options[option]).flatten.tap do |paths|
64 | cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
65 | end
66 | end
67 | cmd_args += sources.flatten.uniq
68 | unless Buildr.application.options.dryrun
69 | info "Generating Javadoc for #{project.name}"
70 | trace (['javadoc'] + cmd_args).join(' ')
71 | Java.load
72 | Java.com.sun.tools.javadoc.Main.execute(cmd_args.to_java(Java.java.lang.String)) == 0 or
73 | fail 'Failed to generate Javadocs, see errors above'
74 | end
75 | end
76 | end
77 | end
78 |
79 | class Project #:nodoc:
80 | include JavadocDefaults
81 | end
82 | end
83 |
84 | Buildr::Doc.engines << Buildr::Doc::Javadoc
85 |
--------------------------------------------------------------------------------
/lib/buildr/core/help.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr #:nodoc:
17 |
18 | module Help #:nodoc:
19 | class << self
20 |
21 | def <<(arg)
22 | if arg.respond_to?(:call)
23 | texters << arg
24 | else
25 | texters << lambda { arg }
26 | end
27 | end
28 |
29 | def to_s
30 | texters.map(&:call).join("\n")
31 | end
32 |
33 | protected
34 | def texters
35 | @texters ||= []
36 | end
37 |
38 | end
39 | end
40 |
41 | class << self
42 | def help(&block)
43 | Help << block if block_given?
44 | Help
45 | end
46 | end
47 |
48 | end
49 |
50 |
51 | task 'help' do
52 | # Greeter
53 | puts 'Usage:'
54 | puts ' buildr [-f rakefile] {options} targets...'
55 | puts
56 |
57 | # Show only the top-level projects.
58 | projects.reject(&:parent).tap do |top_level|
59 | unless top_level.empty?
60 | puts 'Top-level projects (buildr help:projects for full list):'
61 | width = [top_level.map(&:name).map(&:size), 20].flatten.max
62 | top_level.each do |project|
63 | puts project.comment.to_s.empty? ? project.name : (" %-#{width}s # %s" % [project.name, project.comment])
64 | end
65 | puts
66 | end
67 | end
68 |
69 | # Show all the top-level tasks, excluding projects.
70 | puts 'Common tasks:'
71 | task('help:tasks').invoke
72 | puts
73 | puts 'For help on command line options:'
74 | puts ' buildr --help'
75 | puts Buildr.help.to_s
76 | end
77 |
78 |
79 | module Buildr
80 |
81 | # :call-seq:
82 | # help() { ... }
83 | #
84 | # Use this to enhance the help task, e.g. to print some important information about your build,
85 | # configuration options, build instructions, etc.
86 | def help(&block)
87 | Buildr.help << block
88 | end
89 |
90 | end
91 |
92 |
93 | namespace 'help' do
94 |
95 | desc 'List all projects defined by this buildfile'
96 | task 'projects' do
97 | width = projects.map(&:name).map(&:size).max
98 | projects.each do |project|
99 | puts project.comment.to_s.empty? ? " #{project.name}" : (" %-#{width}s # %s" % [project.name, project.comment])
100 | end
101 | end
102 |
103 | desc 'List all tasks available from this buildfile'
104 | task 'tasks' do
105 | Buildr.application.tasks.select(&:comment).reject { |task| Project === task }.tap do |tasks|
106 | width = [tasks.map(&:name).map(&:size), 20].flatten.max
107 | tasks.each do |task|
108 | printf " %-#{width}s # %s\n", task.name, task.comment
109 | end
110 | puts
111 | end
112 | end
113 |
114 | end
115 |
--------------------------------------------------------------------------------
/addon/buildr/css_lint-report.xsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
21 |
22 |
23 |
24 |
25 | CssLint Violations
26 |
27 |
28 |
29 | Coding Style Check Results
30 |
31 |
32 |
33 | |
34 | Summary
35 | |
36 |
37 |
38 | | Files with errors |
39 |
40 |
41 | |
42 |
43 |
44 | | Total errors |
45 |
46 |
47 | |
48 |
49 |
50 |
51 | The following are violations of the ScssLint Rules:
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | | File: |
62 |
63 |
64 | |
65 |
66 |
67 |
68 |
69 | | Line |
70 | Column |
71 | Severity |
72 | Reason |
73 | Evidence |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 | |
83 |
84 | |
85 |
86 |
87 | |
88 |
89 |
90 | |
91 |
92 |
93 | |
94 |
95 |
96 | |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/addon/buildr/checkstyle-report.xsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
21 |
22 |
23 |
24 |
25 | Checkstyle Violations
26 |
27 |
28 |
29 | Coding Style Check Results
30 |
31 |
32 |
33 | |
34 | Summary
35 | |
36 |
37 |
38 | | Total files checked |
39 |
40 |
41 | |
42 |
43 |
44 | | Files with errors |
45 |
46 |
47 | |
48 |
49 |
50 | | Total errors |
51 |
52 |
53 | |
54 |
55 |
56 | | Errors per file |
57 |
58 |
59 | |
60 |
61 |
62 |
63 | The following are violations of the Checkstyle Rules:
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | | File: |
74 |
75 |
76 | |
77 |
78 |
79 |
80 |
81 | | Line Number |
82 | Error Message |
83 | Check |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | |
93 |
94 | |
95 |
96 |
97 | |
98 |
99 |
100 | |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/addon/buildr/openjpa.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr
17 |
18 | # Provides OpenJPA bytecode enhancement and Mapping tool task. Require explicitly using require "buildr/openjpa".
19 | module OpenJPA
20 |
21 | VERSION = "1.0.1"
22 |
23 | REQUIRES = [ "org.apache.openjpa:openjpa:jar:#{VERSION}",
24 | "commons-collections:commons-collections:jar:3.1",
25 | "commons-dbcp:commons-dbcp:jar:1.2.1",
26 | "commons-lang:commons-lang:jar:2.1",
27 | "commons-pool:commons-pool:jar:1.2",
28 | "javax.persistence:persistence-api:jar:1.0",
29 | "org.apache.geronimo.specs:geronimo-j2ee-connector_1.5_spec:jar:1.0",
30 | "org.apache.geronimo.specs:geronimo-jta_1.0.1B_spec:jar:1.0",
31 | "net.sourceforge.serp:serp:jar:1.11.0" ]
32 |
33 | class << self
34 |
35 | def enhance(options)
36 | rake_check_options options, :classpath, :properties, :output
37 | artifacts = Buildr.artifacts(options[:classpath]).each { |a| a.invoke }.map(&:to_s) + [options[:output].to_s]
38 | properties = file(options[:properties]).tap { |task| task.invoke }.to_s
39 |
40 | Buildr.ant "openjpa" do |ant|
41 | ant.taskdef :name=>"enhancer", :classname=>"org.apache.openjpa.ant.PCEnhancerTask",
42 | :classpath=>requires.join(File::PATH_SEPARATOR)
43 | ant.enhancer :directory=>options[:output].to_s do
44 | ant.config :propertiesFile=>properties
45 | ant.classpath :path=>artifacts.join(File::PATH_SEPARATOR)
46 | end
47 | end
48 | end
49 |
50 | def mapping_tool(options)
51 | rake_check_options options, :classpath, :properties, :sql, :action
52 | artifacts = Buildr.artifacts(options[:classpath]).each{ |a| a.invoke }.map(&:to_s)
53 | properties = file(options[:properties].to_s).tap { |task| task.invoke }.to_s
54 |
55 | Buildr.ant("openjpa") do |ant|
56 | ant.taskdef :name=>"mapping", :classname=>"org.apache.openjpa.jdbc.ant.MappingToolTask",
57 | :classpath=>requires.join(File::PATH_SEPARATOR)
58 | ant.mapping :schemaAction=>options[:action], :sqlFile=>options[:sql].to_s, :ignoreErrors=>"true" do
59 | ant.config :propertiesFile=>properties
60 | ant.classpath :path=>artifacts.join(File::PATH_SEPARATOR)
61 | end
62 | end
63 | end
64 |
65 | private
66 |
67 | def requires()
68 | @requires ||= Buildr.artifacts(REQUIRES).each { |artifact| artifact.invoke }.map(&:to_s)
69 | end
70 |
71 | end
72 |
73 | def open_jpa_enhance(options = nil)
74 | jpa_options = { :output=>compile.target, :classpath=>compile.dependencies,
75 | :properties=>path_to(:source, :main, :resources, 'META-INF/persistence.xml') }
76 | OpenJPA.enhance jpa_options.merge(options || {})
77 | end
78 |
79 | end
80 |
81 | class Project
82 | include OpenJPA
83 | end
84 | end
85 |
--------------------------------------------------------------------------------
/spec/core/run_spec.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
17 |
18 | describe Project, :run do
19 |
20 | it 'should return the project\'s run task' do
21 | define('foo')
22 | project('foo').run.name.should eql('foo:run')
23 | end
24 |
25 | it 'should return a RunTask' do
26 | define('foo')
27 | project('foo').run.should be_kind_of(Run::RunTask)
28 | end
29 |
30 | it 'should include compile dependencies' do
31 | define('foo') do
32 | compile.using(:javac).with 'group:compile:jar:1.0'
33 | test.compile.using(:javac).with 'group:test:jar:1.0'
34 | end
35 | project('foo').run.classpath.should include(artifact('group:compile:jar:1.0'))
36 | end
37 |
38 | it 'should not include test dependencies' do
39 | define('foo') do
40 | compile.using(:javac).with 'group:compile:jar:1.0'
41 | test.compile.using(:javac).with 'group:test:jar:1.0'
42 | end
43 | project('foo').run.classpath.should_not include(artifact('group:test:jar:1.0'))
44 | end
45 |
46 | it 'should respond to using() and return self' do
47 | define 'foo' do
48 | run.using(:foo=>'Fooing').should be(run)
49 | end
50 | end
51 |
52 | it 'should respond to using() and accept options' do
53 | define 'foo' do
54 | run.using :foo=>'Fooing'
55 | end
56 | project('foo').run.options[:foo].should eql('Fooing')
57 | end
58 |
59 | it 'should select runner using run.using' do
60 | define 'foo' do
61 | run.using :java
62 | end
63 | project('foo').run.runner.should be_a(Run::JavaRunner)
64 | end
65 |
66 | it 'should select runner based on compile language' do
67 | write 'src/main/java/Test.java', 'class Test {}'
68 | define 'foo' do
69 | # compile language detected as :java
70 | end
71 | project('foo').run.runner.should be_a(Run::JavaRunner)
72 | end
73 |
74 | it "should run with the project resources" do
75 | write 'src/main/java/Test.java', 'class Test {}'
76 | write 'src/main/resources/test.properties', ''
77 | define 'foo'
78 | project('foo').run.classpath.should include project('foo').resources.target
79 | end
80 |
81 | it 'should depend on project''s compile task' do
82 | define 'foo'
83 | project('foo').run.prerequisites.should include(project('foo').compile)
84 | end
85 |
86 | it 'should be local task' do
87 | define 'foo' do
88 | define('bar')
89 | end
90 | project('foo:bar').run.should_receive(:invoke_prerequisites)
91 | project('foo:bar').run.should_receive(:run)
92 | in_original_dir(project('foo:bar').base_dir) { task('run').invoke }
93 | end
94 |
95 | it 'should not recurse' do
96 | define 'foo' do
97 | define('bar') { run.using :java, :main => 'foo' }
98 | end
99 | project('foo:bar').run.should_not_receive(:invoke_prerequisites)
100 | project('foo:bar').run.should_not_receive(:run)
101 | project('foo').run.should_receive(:run)
102 | project('foo').run.invoke
103 | end
104 |
105 | end
106 |
--------------------------------------------------------------------------------
/spec/xpath_matchers.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | require 'rexml/document'
17 | require 'rexml/element'
18 |
19 | module RSpec
20 | module Matchers
21 |
22 | # check if the xpath exists one or more times
23 | class HaveXpath
24 | def initialize(xpath)
25 | @xpath = xpath
26 | end
27 |
28 | def matches?(response)
29 | @response = response
30 | doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response)
31 | match = REXML::XPath.match(doc, @xpath)
32 | !match.empty?
33 | end
34 |
35 | def failure_message
36 | "Did not find expected xpath #{@xpath}"
37 | end
38 |
39 | def negative_failure_message
40 | "Did find unexpected xpath #{@xpath}"
41 | end
42 |
43 | def description
44 | "match the xpath expression #{@xpath}"
45 | end
46 | end
47 |
48 | def have_xpath(xpath)
49 | HaveXpath.new(xpath)
50 | end
51 |
52 | # check if the xpath has the specified value
53 | # value is a string and there must be a single result to match its
54 | # equality against
55 | class MatchXpath
56 | def initialize(xpath, val)
57 | @xpath = xpath
58 | @val= val
59 | end
60 |
61 | def matches?(response)
62 | @response = response
63 | doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response)
64 | ok = false
65 | REXML::XPath.each(doc, @xpath) do |e|
66 | @actual_val = case e
67 | when REXML::Attribute
68 | e.to_s
69 | when REXML::Element
70 | e.text
71 | else
72 | e.to_s
73 | end
74 | ok = true
75 | return false unless @val == @actual_val
76 | end
77 | return ok
78 | end
79 |
80 | def failure_message
81 | "The xpath #{@xpath} did not have the value '#{@val}' It was '#{@actual_val}'"
82 | end
83 |
84 | def description
85 | "match the xpath expression #{@xpath} with #{@val}"
86 | end
87 | end
88 |
89 | def match_xpath(xpath, val)
90 | MatchXpath.new(xpath, val)
91 | end
92 |
93 | # checks if the given xpath occurs num times
94 | class HaveNodes #:nodoc:
95 | def initialize(xpath, num)
96 | @xpath= xpath
97 | @num = num
98 | end
99 |
100 | def matches?(response)
101 | @response = response
102 | doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response)
103 | match = REXML::XPath.match(doc, @xpath)
104 | @num_found= match.size
105 | @num_found == @num
106 | end
107 |
108 | def failure_message
109 | "Did not find expected number of nodes #{@num} in xpath #{@xpath} Found #{@num_found}"
110 | end
111 |
112 | def description
113 | "match the number of nodes #{@num}"
114 | end
115 | end
116 |
117 | def have_nodes(xpath, num)
118 | HaveNodes.new(xpath, num)
119 | end
120 |
121 | end
122 | end
123 |
--------------------------------------------------------------------------------
/addon/buildr/xmlbeans.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr
17 |
18 | # Provides XMLBeans schema compiler. Require explicitly using require "buildr/xmlbeans".
19 | #
20 | # require 'buildr/xmlbeans'
21 | # define 'some_proj' do
22 | # compile_xml_beans _(:source, :main, :xsd) # the directory with *.xsd
23 | # end
24 | module XMLBeans
25 |
26 | # You can use ArtifactNamespace to customize the versions of
27 | # :xmlbeans or :stax used by this module:
28 | #
29 | # require 'buildr/xmlbeans'
30 | # Buildr::XMLBeans::REQUIRES.xmlbeans = '2.2.0'
31 | REQUIRES = ArtifactNamespace.for(self) do |ns|
32 | ns.xmlbeans! 'org.apache.xmlbeans:xmlbeans:jar:2.3.0', '>2'
33 | ns.stax_api! 'stax:stax-api:jar:>=1.0.1'
34 | end
35 |
36 | class << self
37 |
38 | def compile(*args)
39 | options = Hash === args.last ? args.pop : {}
40 | options[:verbose] ||= trace?(:xmlbeans)
41 | rake_check_options options, :verbose, :noop, :javasource, :jar, :compile, :output, :xsb
42 | puts "Running XMLBeans schema compiler" if verbose
43 | Buildr.ant "xmlbeans" do |ant|
44 | ant.taskdef :name=>"xmlbeans", :classname=>"org.apache.xmlbeans.impl.tool.XMLBean",
45 | :classpath=>requires.join(File::PATH_SEPARATOR)
46 | ant.xmlbeans :srconly=>"true", :srcgendir=>options[:output].to_s, :classgendir=>options[:output].to_s,
47 | :javasource=>options[:javasource] do
48 | args.flatten.each { |file| ant.fileset File.directory?(file) ? { :dir=>file } : { :file=>file } }
49 | end
50 | end
51 | # Touch paths to let other tasks know there's an update.
52 | touch options[:output].to_s, :verbose=>false
53 | end
54 |
55 | def requires()
56 | @requires ||= REQUIRES.artifacts
57 | end
58 | end
59 |
60 | def compile_xml_beans(*args)
61 | # Run whenever XSD file changes, but typically we're given an directory of XSD files, or even file patterns
62 | # (the last FileList is there to deal with things like *.xsdconfig).
63 | files = args.flatten.map { |file| File.directory?(file) ? FileList["#{file}/*.xsd"] : FileList[file] }.flatten
64 | # Generate sources and add them to the compile task.
65 | generated = file(path_to(:target, :generated, :xmlbeans)=>files) do |task|
66 | XMLBeans.compile args.flatten, :output=>task.name,
67 | :javasource=>compile.options.source, :xsb=>compile.target
68 | end
69 | compile.using(:javac).from(generated).with(*XMLBeans.requires)
70 | # Once compiled, we need to copy the generated XSB/XSD and one (magical?) class file
71 | # into the target directory, or the rest is useless.
72 | compile do |task|
73 | verbose(false) do
74 | base = generated.to_s
75 | FileList["#{base}/**/*.{class,xsb,xsd}"].each do |file|
76 | target = File.join(compile.target.to_s, Util.relative_path(file, base))
77 | mkpath File.dirname(target) ; cp file, target
78 | end
79 | end
80 | end
81 | end
82 |
83 | end
84 |
85 | class Project
86 | include XMLBeans
87 | end
88 | end
89 |
--------------------------------------------------------------------------------
/spec/scala/doc_spec.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 |
17 | require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18 |
19 | describe "Scaladoc" do
20 |
21 | it 'should pick -doc-title from project name by default' do
22 | define 'foo' do
23 | compile.using(:scalac)
24 |
25 | define 'bar' do
26 | compile.using(:scalac)
27 | end
28 | end
29 |
30 | project('foo').doc.options[:"doc-title"].should eql('foo')
31 | project('foo:bar').doc.options[:"doc-title"].should eql('foo:bar')
32 | end
33 |
34 | it 'should pick -doc-title from project description by default, if available' do
35 | desc 'My App'
36 | define 'foo' do
37 | compile.using(:scalac)
38 | end
39 | project('foo').doc.options[:"doc-title"].should eql('My App')
40 | end
41 |
42 | it 'should not override explicit "doc-title" option' do
43 | define 'foo' do
44 | compile.using(:scalac)
45 | doc.using "doc-title" => 'explicit'
46 | end
47 | project('foo').doc.options[:"doc-title"].should eql('explicit')
48 | end
49 |
50 | if Java.java.lang.System.getProperty("java.runtime.version") >= "1.6"
51 |
52 | it 'should convert :windowtitle to -doc-title for Scala 2.8.1 and later' do
53 | write 'src/main/scala/com/example/Test.scala', 'package com.example; class Test { val i = 1 }'
54 | define('foo') do
55 | doc.using :windowtitle => "foo"
56 | end
57 | actual = Java.scala.tools.nsc.ScalaDoc.new
58 | scaladoc = Java.scala.tools.nsc.ScalaDoc.new
59 | Java.scala.tools.nsc.ScalaDoc.should_receive(:new) do
60 | scaladoc
61 | end
62 | scaladoc.should_receive(:process) do |args|
63 | # Convert Java Strings to Ruby Strings, if needed.
64 | xargs = args.map { |a| a.is_a?(String) ? a : a.toString }
65 | xargs.should include("-doc-title")
66 | xargs.should_not include("-windowtitle")
67 | actual.process(args).should eql(true)
68 | end
69 | project('foo').doc.invoke
70 | end unless Buildr::Scala.version?(2.7, "2.8.0")
71 |
72 | elsif Buildr::VERSION >= '1.5'
73 | raise "JVM version guard in #{__FILE__} should be removed since it is assumed that Java 1.5 is no longer supported."
74 | end
75 |
76 | end
77 |
78 | if Java.java.lang.System.getProperty("java.runtime.version") >= "1.6"
79 |
80 | describe "package(:scaladoc)" do
81 | it "should generate target/project-version-scaladoc.jar" do
82 | write 'src/main/scala/Foo.scala', 'class Foo'
83 | define 'foo', :version=>'1.0' do
84 | package(:scaladoc)
85 | end
86 |
87 | scaladoc = project('foo').package(:scaladoc)
88 | scaladoc.should point_to_path('target/foo-1.0-scaladoc.jar')
89 |
90 | lambda {
91 | project('foo').task('package').invoke
92 | }.should change { File.exist?('target/foo-1.0-scaladoc.jar') }.to(true)
93 |
94 | scaladoc.should exist
95 | scaladoc.should contain('index.html')
96 | scaladoc.should contain('Foo.html')
97 | end
98 | end
99 |
100 | elsif Buildr::VERSION >= '1.5'
101 | raise "JVM version guard in #{__FILE__} should be removed since it is assumed that Java 1.5 is no longer supported."
102 | end
103 |
--------------------------------------------------------------------------------
/lib/buildr/groovy/bdd.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | # The Groovy module
17 | module Buildr::Groovy
18 |
19 | # EasyB is a Groovy based BDD framework.
20 | # To use in your project:
21 | #
22 | # test.using :easyb
23 | #
24 | # This framework will search in your project for:
25 | # src/spec/groovy/**/*Story.groovy
26 | # src/spec/groovy/**/*Specification.groovy
27 | #
28 | # Support the following options:
29 | # * :format -- Report format :txt or :xml, default is :txt
30 | # * :properties -- Hash of properties passed to the test suite.
31 | # * :java_args -- Arguments passed to the JVM.
32 | class EasyB < TestFramework::JavaBDD
33 | @lang = :groovy
34 | @bdd_dir = :spec
35 |
36 | VERSION = "0.9"
37 | TESTS_PATTERN = [ /(Story|Specification).groovy$/ ]
38 | OPTIONS = [:format, :properties, :java_args]
39 |
40 | class << self
41 | def version
42 | Buildr.settings.build['jbehave'] || VERSION
43 | end
44 |
45 | def dependencies
46 | @dependencies ||= ["org.easyb:easyb:jar:#{version}",
47 | 'org.codehaus.groovy:groovy:jar:1.5.3','asm:asm:jar:2.2.3',
48 | 'commons-cli:commons-cli:jar:1.0','antlr:antlr:jar:2.7.7']
49 | end
50 |
51 | def applies_to?(project) #:nodoc:
52 | %w{
53 | **/*Specification.groovy **/*Story.groovy
54 | }.any? { |glob| !Dir[project.path_to(:source, bdd_dir, lang, glob)].empty? }
55 | end
56 |
57 | private
58 | def const_missing(const)
59 | return super unless const == :REQUIRES # TODO: remove in 1.5
60 | Buildr.application.deprecated "Please use JBehave.dependencies/.version instead of JBehave::REQUIRES/VERSION"
61 | dependencies
62 | end
63 | end
64 |
65 | def tests(dependencies) #:nodoc:
66 | Dir[task.project.path_to(:source, bdd_dir, lang, "**/*.groovy")].
67 | select { |name| TESTS_PATTERN.any? { |pat| pat === name } }
68 | end
69 |
70 | def run(tests, dependencies) #:nodoc:
71 | options = { :format => :txt }.merge(self.options).only(*OPTIONS)
72 |
73 | if :txt == options[:format]
74 | easyb_format, ext = 'txtstory', '.txt'
75 | elsif :xml == options[:format]
76 | easyb_format, ext = 'xmlbehavior', '.xml'
77 | else
78 | raise "Invalid format #{options[:format]} expected one of :txt :xml"
79 | end
80 |
81 | cmd_args = [ 'org.disco.easyb.BehaviorRunner' ]
82 | cmd_options = { :properties => options[:properties],
83 | :java_args => options[:java_args],
84 | :classpath => dependencies }
85 |
86 | tests.inject([]) do |passed, test|
87 | name = test.sub(/.*?groovy[\/\\]/, '').pathmap('%X')
88 | report = File.join(task.report_to.to_s, name + ext)
89 | mkpath report.pathmap('%d')
90 | begin
91 | Java::Commands.java cmd_args,
92 | "-#{easyb_format}", report,
93 | test, cmd_options.merge(:name => name)
94 | rescue => e
95 | passed
96 | else
97 | passed << test
98 | end
99 | end
100 | end
101 |
102 | end # EasyB
103 |
104 | end
105 |
106 | Buildr::TestFramework << Buildr::Groovy::EasyB
107 |
--------------------------------------------------------------------------------
/rakelib/all-in-one.rake:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | def workspace_dir
17 | "#{File.expand_path(File.join(File.dirname(__FILE__), ".."))}"
18 | end
19 |
20 | desc 'Create JRuby all-in-one distribution'
21 | task 'all-in-one' => 'all-in-one:all-in-one'
22 |
23 | namespace 'all-in-one' do
24 |
25 | version = '1.7.0'
26 | jruby_distro = "jruby-bin-#{version}.tar.gz"
27 | url = "http://jruby.org.s3.amazonaws.com/downloads/#{version}/#{jruby_distro}"
28 | dir = "jruby-#{version}"
29 |
30 | task 'all-in-one' => %w(gem prepare download_and_extract install_dependencies clean_dist package)
31 |
32 | desc 'Prepare to run'
33 | task 'prepare' do
34 | mkpath '_all-in-one'
35 | cd '_all-in-one'
36 | end
37 |
38 | desc 'Download and extract JRuby'
39 | task 'download_and_extract' do
40 | unless File.exist?(jruby_distro)
41 | puts "Downloading JRuby from #{url} ..."
42 | require 'open-uri'
43 | File.open(jruby_distro, "wb") do |saved_file|
44 | # the following "open" is provided by open-uri
45 | open(url) do |read_file|
46 | saved_file.write(read_file.read)
47 | end
48 | end
49 | puts '[X] Downloaded JRuby'
50 | end
51 |
52 | rm_rf dir if File.exist? dir
53 |
54 | puts "Extracting JRuby to #{dir} ..."
55 | sh 'tar', 'xzf', jruby_distro
56 | puts '[X] Extracted JRuby'
57 | cd dir
58 | end
59 |
60 | desc 'Cleanup JRuby distribution'
61 | task 'clean_dist' do
62 | puts 'Cleaning...'
63 | mv 'tool/nailgun/ng.exe', 'bin'
64 | rm_rf 'tool'
65 | rm_rf 'docs'
66 | rm_rf 'lib/ruby/1.8'
67 | rm_rf 'lib/ruby/gems/1.9/doc'
68 | rm_rf 'lib/ruby/gems/shared/doc'
69 | rm_rf 'samples'
70 | end
71 |
72 | desc 'Install Buildr gem and dependencies'
73 | task 'install_dependencies' do
74 | puts 'Install Buildr gem ...'
75 | java_gem = FileList["../../pkg/buildr-#{spec.version}-java.gem"].first
76 | command = ['bin/jruby', '-S', 'gem', 'install', java_gem, '--no-rdoc', '--no-ri', '--env-shebang']
77 | system({'GEM_HOME' => nil, 'GEM_PATH' => nil, 'MY_RUBY_HOME' => nil, 'RUBYOPT' => nil}, *command)
78 | puts '[X] Install Buildr gem'
79 | end
80 |
81 | desc 'Package distribution'
82 | task 'package' do
83 | pkg_dir = "#{workspace_dir}/pkg"
84 | mkpath pkg_dir
85 | puts 'Zipping distribution ...'
86 | cd '..'
87 | new_dir = "#{spec.name}-all-in-one-#{spec.version}"
88 | rm_rf new_dir
89 | mkdir new_dir
90 | mv dir, "#{new_dir}/embedded"
91 | mkdir "#{new_dir}/bin"
92 | cp "#{workspace_dir}/all-in-one/buildr", "#{new_dir}/bin/buildr"
93 | cp "#{workspace_dir}/all-in-one/buildr.cmd", "#{new_dir}/bin/buildr.cmd"
94 | File.chmod(0500, "#{new_dir}/bin/buildr", "#{new_dir}/bin/buildr.cmd")
95 | zip = "#{pkg_dir}/#{new_dir}.zip"
96 | rm zip if File.exist? zip
97 | sh 'zip', '-q', '-r', zip, new_dir
98 | puts '[X] Zipped distribution'
99 |
100 | puts 'Tarring distribution ...'
101 | tar = "#{pkg_dir}/#{new_dir}.tar.gz"
102 | rm tar if File.exist? tar
103 | sh 'tar', 'czf', tar, new_dir
104 | puts '[X] Tarred distribution'
105 |
106 | rm_rf new_dir
107 | end
108 |
109 | end
110 |
111 | task('clobber') { rm_rf '_all-in-one' }
112 |
--------------------------------------------------------------------------------
/lib/buildr/core/environment.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | module Buildr #:nodoc:
17 |
18 | # Collection of options for controlling Buildr.
19 | class Options
20 |
21 | # We use this to present environment variable as arrays.
22 | class EnvArray < Array #:nodoc:
23 |
24 | def initialize(name)
25 | @name = name.upcase
26 | replace((ENV[@name] || ENV[@name.downcase] || '').split(/\s*,\s*/).reject(&:empty?))
27 | end
28 |
29 | (Array.instance_methods - Object.instance_methods - Enumerable.instance_methods - ['each']).sort.each do |method|
30 | class_eval %{def #{method}(*args, &block) ; result = super ; write_envarray ; result ; end}
31 | end
32 |
33 | private
34 |
35 | def write_envarray
36 | ENV[@name.downcase] = nil
37 | ENV[@name] = map(&:to_s).join(',')
38 | end
39 |
40 | end
41 |
42 |
43 | # Wraps around the proxy environment variables:
44 | # * :http -- HTTP_PROXY
45 | # * :https -- HTTPS_PROXY
46 | # * :exclude -- NO_PROXY
47 | class Proxies
48 |
49 | # Returns the HTTP_PROXY URL.
50 | def http
51 | ENV['HTTP_PROXY'] || ENV['http_proxy']
52 | end
53 |
54 | # Sets the HTTP_PROXY URL.
55 | def http=(url)
56 | ENV['http_proxy'] = nil
57 | ENV['HTTP_PROXY'] = url
58 | end
59 |
60 | # Returns the HTTPS_PROXY URL.
61 | def https
62 | ENV['HTTPS_PROXY'] || ENV['https_proxy']
63 | end
64 |
65 | # Sets the HTTPS_PROXY URL.
66 | def https=(url)
67 | ENV['https_proxy'] = nil
68 | ENV['HTTPS_PROXY'] = url
69 | end
70 |
71 | # Returns list of hosts to exclude from proxying (NO_PROXY).
72 | def exclude
73 | @exclude ||= EnvArray.new('NO_PROXY')
74 | end
75 |
76 | # Sets list of hosts to exclude from proxy (NO_PROXY). Accepts host name, array of names,
77 | # or nil to clear the list.
78 | def exclude=(url)
79 | exclude.clear
80 | exclude.concat [url].flatten if url
81 | exclude
82 | end
83 |
84 | end
85 |
86 | # :call-seq:
87 | # proxy => options
88 | #
89 | # Returns the proxy options. Currently supported options are:
90 | # * :http -- HTTP proxy for use when downloading.
91 | # * :exclude -- Do not use proxy for these hosts/domains.
92 | #
93 | # For example:
94 | # options.proxy.http = 'http://proxy.acme.com:8080'
95 | # You can also set it using the environment variable HTTP_PROXY.
96 | #
97 | # You can exclude individual hosts from being proxied, or entire domains, for example:
98 | # options.proxy.exclude = 'optimus'
99 | # options.proxy.exclude = ['optimus', 'prime']
100 | # options.proxy.exclude << '*.internal'
101 | def proxy
102 | @proxy ||= Proxies.new
103 | end
104 |
105 | end
106 |
107 |
108 | class << self
109 |
110 | # :call-seq:
111 | # options => Options
112 | #
113 | # Returns the Buildr options. See Options.
114 | def options
115 | @options ||= Options.new
116 | end
117 |
118 | end
119 |
120 | # :call-seq:
121 | # options => Options
122 | #
123 | # Returns the Buildr options. See Options.
124 | def options
125 | Buildr.options
126 | end
127 |
128 | end
129 |
--------------------------------------------------------------------------------
/lib/buildr.rb:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with this
3 | # work for additional information regarding copyright ownership. The ASF
4 | # licenses this file to you under the Apache License, Version 2.0 (the
5 | # "License"); you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 |
16 | unless defined?(Buildr::VERSION)
17 | require 'buildr/version'
18 | end
19 |
20 | require 'rake'
21 | include Rake::DSL
22 | Rake::TaskManager.record_task_metadata = true
23 |
24 | require 'rbconfig'
25 | require 'pathname'
26 | autoload :Tempfile, 'tempfile'
27 | autoload :YAML, 'yaml'
28 | autoload :REXML, 'rexml/document'
29 | autoload :XmlSimple, 'xmlsimple'
30 | autoload :Builder, 'builder' # A different kind of buildr, one we use to create XML.
31 | autoload :RSpec, 'rspec'
32 | require 'erb'
33 | require 'find'
34 | require 'uri'
35 | require 'stringio'
36 | require 'fileutils'
37 | require 'orderedhash'
38 | require 'securerandom'
39 |
40 | require 'buildr/core/util'
41 | require 'buildr/core/console'
42 | require 'buildr/core/common'
43 | require 'buildr/core/application'
44 | require 'buildr/core/jrebel'
45 | require 'buildr/core/project'
46 | require 'buildr/core/assets'
47 | require 'buildr/core/environment'
48 | require 'buildr/core/help'
49 | require 'buildr/core/checks'
50 | require 'buildr/core/build'
51 | require 'buildr/core/filter'
52 | require 'buildr/core/compile'
53 | require 'buildr/core/test'
54 | require 'buildr/shell'
55 | require 'buildr/java/commands'
56 | require 'buildr/core/shell'
57 | require 'buildr/run'
58 | require 'buildr/core/run'
59 | require 'buildr/core/transports'
60 | require 'buildr/java/pom'
61 | require 'buildr/core/generate'
62 | require 'buildr/core/cc'
63 | require 'buildr/core/doc'
64 | require 'buildr/core/osx' if RUBY_PLATFORM =~ /darwin/
65 | require 'buildr/core/linux' if RUBY_PLATFORM =~ /linux/
66 | require 'buildr/packaging/version_requirement'
67 | require 'buildr/packaging/artifact_namespace'
68 | require 'buildr/packaging/artifact'
69 | require 'buildr/packaging/package'
70 | require 'buildr/packaging/archive'
71 | require 'buildr/packaging/ziptask'
72 | require 'buildr/packaging/tar'
73 | require 'buildr/packaging/gems'
74 | require 'buildr/packaging/zip'
75 | require 'buildr/packaging/test_jar'
76 | require RUBY_PLATFORM == 'java' ? 'buildr/java/jruby' : 'buildr/java/rjb'
77 | require 'buildr/java/ant'
78 | require 'buildr/java/compiler'
79 | require 'buildr/java/external'
80 | require 'buildr/java/tests'
81 | require 'buildr/java/test_result'
82 | require 'buildr/java/bdd'
83 | require 'buildr/java/packaging'
84 | require 'buildr/java/commands'
85 | require 'buildr/java/doc'
86 | require 'buildr/java/deprecated'
87 | require 'buildr/ide/idea'
88 | require 'buildr/ide/eclipse'
89 |
90 | # Methods defined in Buildr are both instance methods (e.g. when included in Project)
91 | # and class methods when invoked like Buildr.artifacts().
92 | module Buildr ; extend self ; end
93 |
94 | # The Buildfile object (self) has access to all the Buildr methods and constants.
95 | class << self ; include Buildr ; end
96 |
97 | # All modules defined under Buildr::* can be referenced without Buildr:: prefix
98 | # unless a conflict exists (e.g. Buildr::RSpec vs ::RSpec)
99 | class Object #:nodoc:
100 | Buildr.constants.each do |name|
101 | const = Buildr.const_get(name)
102 | if const.is_a?(Module)
103 | const_set name, const unless const_defined?(name)
104 | end
105 | end
106 | end
107 |
108 | # Need to set this again as jruby was not correctly
109 | # initialized, the first time it was called
110 | Buildr::Console.use_color = $stdout.isatty
111 |
--------------------------------------------------------------------------------
/README.rdoc:
--------------------------------------------------------------------------------
1 | = Buildr
2 |
3 | This is Buildr, the build system that lets you build like you code.
4 |
5 | http://buildr.apache.org/
6 |
7 | == Get Started
8 |
9 | === Install Buildr
10 |
11 | Buildr needs Ruby 1.8 or later and RubyGems 0.9 or later.
12 |
13 | Windows users can get the one-click Ruby installer, which includes the latest
14 | version of Ruby and RubyGems:
15 |
16 | http://rubyinstaller.org
17 |
18 | Make sure to set JAVA_HOME environment variable first, then:
19 |
20 | gem install buildr
21 |
22 | (Use sudo for Linux and OS X)
23 |
24 | More installation and setup instructions available online
25 | http://buildr.apache.org/
26 |
27 |
28 | === RTFM
29 |
30 | * Buildr documentation: http://buildr.apache.org
31 | * More about Rake: http://docs.rubyrake.org
32 | * Antwrap documentation: http://antwrap.rubyforge.org
33 |
34 |
35 | === Mailing list
36 |
37 | Users: users-subscribe@buildr.apache.org http://buildr.markmail.org/search/list:users
38 |
39 | Developers: dev-subscribe@buildr.apache.org http://buildr.markmail.org/search/list:dev
40 |
41 | Create your own Buildfile and start living the life!
42 |
43 |
44 | == Where's My Ruby?
45 |
46 | Buildr needs Ruby 1.8 or later and RubyGems 0.9 or later. All other
47 | dependencies are installed when you run:
48 |
49 | gem install buildr
50 |
51 | === Windows
52 |
53 | Windows users can get the one-click Ruby installer, which includes the latest
54 | version of Ruby and RubyGems:
55 |
56 | http://rubyinstaller.org
57 |
58 | Before installing Buildr, please set the JAVA_HOME environment variable to
59 | point to your JDK distribution. Next, use Ruby Gem to install Buildr:
60 |
61 | > gem install buildr
62 |
63 | When prompted for a platform, select mswin32.
64 |
65 | === Linux, BSD, Cygwin
66 |
67 | On Linux/BSD/Cygwin, use your default package manager, for example, for Ubuntu:
68 |
69 | $ sudo apt-get install ruby
70 | $ sudo apt-get install ruby1.8-dev
71 | $ sudo apt-get install build-essential
72 | $ sudo apt-get install libopenssl-ruby
73 |
74 | Before installing Buildr, please set the JAVA_HOME environment variable to
75 | point to your JDK distribution. Next, use Ruby Gem to install Buildr:
76 |
77 | $ sudo env JAVA_HOME=$JAVA_HOME gem install buildr
78 |
79 | When prompted for a platform, select ruby.
80 |
81 | === OS X
82 |
83 | Leopard includes the latest version of Ruby, if you are using Tiger or an older
84 | release, we recommend re-installing the latest:
85 |
86 | http://hivelogic.com/narrative/articles/ruby-rails-mongrel-mysql-osx
87 |
88 | To install Buildr:
89 |
90 | $ sudo gem install buildr
91 |
92 | When prompted for a platform, select ruby.
93 |
94 |
95 | == Living On the Edge
96 |
97 | You can check the latest sources from GIT:
98 |
99 | git clone http://git.apache.org/buildr.git
100 |
101 | If you prefer GitHub, a mirror is available from http://github.com/apache/buildr:
102 |
103 | git clone git://github.com/apache/buildr.git
104 |
105 | To install Buildr locally from source:
106 |
107 | cd buildr
108 | export JRUBY_OPTS="-J-XX:MaxPermSize=312m -J-Xmx1024M"
109 | export JAVA_OPTS="-Xmx1024m -XX:MaxPermSize=312m"
110 | rake install
111 |
112 | If the cutting edge doesn't work, make sure to check the CHANGELOG, to see
113 | which changes might have broken your build. To run all the test cases:
114 |
115 | rake spec
116 |
117 | == License
118 |
119 | Licensed to the Apache Software Foundation (ASF) under one or more
120 | contributor license agreements. See the NOTICE file distributed with this
121 | work for additional information regarding copyright ownership. The ASF
122 | licenses this file to you under the Apache License, Version 2.0 (the
123 | "License"); you may not use this file except in compliance with the License.
124 | You may obtain a copy of the License at
125 |
126 | http://www.apache.org/licenses/LICENSE-2.0
127 |
128 | Unless required by applicable law or agreed to in writing, software
129 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
130 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
131 | License for the specific language governing permissions and limitations under
132 | the License.
133 |
--------------------------------------------------------------------------------