Buildr 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ module Buildr
2
+
3
+ module OpenJPA
4
+
5
+ VERSION = "0.9.7-incubating-SNAPSHOT"
6
+
7
+ REQUIRES = [ "org.apache.openjpa:openjpa-all:jar:#{VERSION}",
8
+ "commons-collections:commons-collections:jar:3.1",
9
+ "commons-dbcp:commons-dbcp:jar:1.2.1",
10
+ "commons-lang:commons-lang:jar:2.1",
11
+ "commons-pool:commons-pool:jar:1.2",
12
+ "javax.persistence:persistence-api:jar:1.0",
13
+ "org.apache.geronimo.specs:geronimo-j2ee-connector_1.5_spec:jar:1.0",
14
+ "org.apache.geronimo.specs:geronimo-jta_1.0.1B_spec:jar:1.0",
15
+ "net.sourceforge.serp:serp:jar:1.11.0" ]
16
+
17
+ OPTIONS = [ :verbose, :noop, :cp, :classpath, :properties ]
18
+
19
+ def self.enhance(options)
20
+ options[:verbose] ||= Rake.application.options.trace || false
21
+ fu_check_options options, *OPTIONS + [:output]
22
+
23
+ runtool options.merge(:class=>"org.apache.openjpa.enhance.PCEnhancer", :name=>"Enhancer",
24
+ :args=>{ "-p"=>options[:properties], "-d"=>options[:output] },
25
+ :classpath=>options[:classpath] + [options[:output]])
26
+ end
27
+
28
+ def self.mapping_tool(options)
29
+ options[:verbose] ||= Rake.application.options.trace || false
30
+ fu_check_options options, *OPTIONS + [:action, :sql]
31
+
32
+ runtool options.merge(:class=>"org.apache.openjpa.jdbc.meta.MappingTool", :name=>"Mapping Tool",
33
+ :args=>{ "-p"=>options[:properties], "-sql"=>options[:sql], "-sa"=>options[:action] })
34
+ end
35
+
36
+ protected
37
+
38
+ def self.runtool(options)
39
+ classpath = (options[:classpath] || []).collect | (options[:cp] || []).collect
40
+ classpath = classpath.each { |t| t.invoke if t.respond_to?(:invoke) }.map(&:to_s)
41
+ cmd_args = ["-cp", (classpath + requires).join(File::PATH_SEPARATOR)]
42
+ cmd_args << options[:class]
43
+ cmd_args += options[:args].select { |n, v| v }.map { |n, v| [ n, v ] }.flatten
44
+ cmd_args << { :verbose=>options[:verbose] }
45
+ unless options[:noop]
46
+ verbose { puts "Running OpenJPA #{options[:name]}" }
47
+ sh(Java.path_to_bin("java"), *cmd_args) { |ok, res| fail "Failed to execute OpenJPA #{options[:name]}, see errors above" unless ok }
48
+ end
49
+ end
50
+
51
+ def self.requires()
52
+ @required ||= artifacts(REQUIRES).each { |artifact| artifact.invoke }.map(&:to_s)
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,214 @@
1
+ module Buildr
2
+ module Java
3
+
4
+ module Packaging
5
+
6
+ MANIFEST_HEADER = "Manifest-Version: 1.0\nCreated-By: Ruby Build System"
7
+
8
+ class JarTask < ZipTask
9
+ attr_accessor :manifest
10
+
11
+ def initialize(*args)
12
+ super
13
+ @manifest = true
14
+ end
15
+
16
+ def []=(key, value)
17
+ if key.to_sym == :manifest
18
+ self.manifest = value
19
+ else
20
+ super key, value
21
+ end
22
+ value
23
+ end
24
+
25
+ protected
26
+
27
+ def create(zip)
28
+ if manifest
29
+ zip.mkdir "META-INF"
30
+ zip.file.open("META-INF/MANIFEST.MF", "w") do |output|
31
+ output.write MANIFEST_HEADER
32
+ case manifest
33
+ when Hash
34
+ output.write manifest.map { |pair| pair.join(": ") }.join("\n")
35
+ when Array
36
+ manifest.each do |section|
37
+ output.write "\n"
38
+ output.write section.map { |pair| pair.join(": ") }.join("\n")
39
+ end
40
+ when Proc, Method
41
+ output.write manifest.call
42
+ when String
43
+ output.write File.read(manifest)
44
+ when true # Default behavior
45
+ end
46
+ output.write "\n"
47
+ end
48
+ end
49
+ super zip
50
+ end
51
+
52
+ end
53
+
54
+ class WarTask < JarTask
55
+
56
+ def []=(key, value)
57
+ case key.to_sym
58
+ when :libs
59
+ self.include artifacts(value), :path=>"WEB-INF/lib"
60
+ when :classes
61
+ self.include value, :path=>"WEB-INF/classes"
62
+ else
63
+ super key, value
64
+ end
65
+ value
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+ end
72
+
73
+
74
+ # Create a JAR from all the pre-requisites.
75
+ #
76
+ # For example:
77
+ # jar "lib-1.0.jar"=>["target/classes", "MANIFEST,MF"]
78
+ def jar(file)
79
+ Packaging::JarTask.define_task(file)
80
+ end
81
+
82
+
83
+ class Project
84
+
85
+ # Group used for packaging. Inherited from parent project.
86
+ inherited_attr :group
87
+ # Version used for packaging. Inherited from parent project.
88
+ inherited_attr :version
89
+
90
+ # The project ID is the project name, and for a sub-project the
91
+ # parent project ID followed by the project name, separated with a
92
+ # hyphen. For example, "foo" and "foo-bar".
93
+ def id()
94
+ name.gsub(":", "-")
95
+ end
96
+ inherited_attr :webapp_src_dir do File.join(src_dir, "main", "webapp") end
97
+
98
+ def package(*args)
99
+ if Hash === args.last
100
+ options = args.pop.dup
101
+ else
102
+ options = {}
103
+ end
104
+ options[:type] = args.shift.to_s if Symbol === args.first
105
+ fail "No packaging type specified" unless options[:type]
106
+ options[:group] ||= self.group
107
+ options[:version] ||= self.version
108
+ options[:id] ||= self.id
109
+ if String === args.first
110
+ file = args.shift
111
+ else
112
+ file = options.delete(:file) || path_to(:target_dir, Artifact.hash_to_file_name(options))
113
+ end
114
+ fail "One argument too many; expecting at most type, file name, and hash of options" unless args.empty?
115
+
116
+ packager = method("package_as_#{options[:type]}") rescue
117
+ fail("Do not know how to create a package of type #{options[:type]}")
118
+ package = packager.call(file, options) or fail("Do not know how to create a package of type #{options[:type]}")
119
+
120
+ task "package"=>package
121
+ package.enhance [ task("build")]
122
+
123
+ task "install"=>(file(repositories.locate(package)=>package) { |task|
124
+ mkpath File.dirname(task.name), :verbose=>false
125
+ cp package.name, task.name
126
+ })
127
+ task "install"=>package.pom
128
+
129
+ task "uninstall" do |task|
130
+ verbose(Rake.application.options.trace) do
131
+ [ package, package.pom ].map { |artifact| repositories.locate(artifact) }.
132
+ each { |file| rm file if File.exist?(file) }
133
+ end
134
+ end
135
+
136
+ task("deploy") { deploy(package, package.pom) }
137
+
138
+ packages << package
139
+ Artifact.register package, package.pom
140
+ package
141
+ end
142
+
143
+ def packages()
144
+ @packages ||= []
145
+ end
146
+
147
+ protected
148
+
149
+ def package_as_jar(file, options)
150
+ unless Rake::Task.task_defined?(file)
151
+ returning(Java::Packaging::JarTask.define_task(file)) do |task|
152
+ package_extend task, options
153
+ task.enhance [path_to(:java_target_dir)]
154
+ task.include path_to(:java_target_dir, "*")
155
+ end
156
+ end
157
+ returning(Java::Packaging::JarTask.define_task(file)) do |task|
158
+ task.include options[:include] if options[:include]
159
+ task.manifest = options[:manifest] if options[:manifest]
160
+ end
161
+ end
162
+
163
+ def package_as_war(file, options)
164
+ unless Rake::Task.task_defined?(file)
165
+ returning(Java::Packaging::WarTask.define_task(file)) do |task|
166
+ package_extend task, options
167
+ task.include path_to(:webapp_src_dir, "*")
168
+ task.with :classes=>path_to(:java_target_dir, "**")
169
+ end
170
+ end
171
+ # Add anything we find in webapp sources directory.
172
+ returning(Java::Packaging::WarTask.define_task(file)) do |task|
173
+ task.include options[:include] if options[:include]
174
+ # Add libraries in WEB-INF lib, and classes in WEB-INF classes
175
+ task.with :libs=>options[:libs].collect if options[:libs]
176
+ task.with :classes=>options[:classes] if options[:classes]
177
+ end
178
+ end
179
+
180
+ def package_as_zip(file, options)
181
+ unless Rake::Task.task_defined?(file)
182
+ returning(ZipTask.define_task(file)) do |task|
183
+ package_extend task, options
184
+ task.include path_to(:java_target_dir, "*")
185
+ end
186
+ end
187
+ returning(ZipTask.define_task(file)) do |task|
188
+ task.include options[:include] if options[:include]
189
+ end
190
+ end
191
+
192
+ def package_extend(task, spec)
193
+ task.extend ActsAsArtifact
194
+ task.apply_spec spec
195
+ task.pom.enhance do |task|
196
+ mkpath File.dirname(task.name), :verbose=>false
197
+ File.open(task.name, "w") do |file|
198
+ xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
199
+ xml.instruct!
200
+ xml.project do
201
+ xml.modelVersion "4.0.0."
202
+ xml.groupId spec[:group]
203
+ xml.artifactId spec[:id]
204
+ xml.version spec[:version]
205
+ xml.classifier spec[:classifier] if spec[:classifier]
206
+ end
207
+ end
208
+ end
209
+ end
210
+
211
+ end
212
+
213
+
214
+ end
@@ -0,0 +1,105 @@
1
+ module Buildr
2
+
3
+ class JUnitTask < Rake::Task
4
+
5
+ attr_accessor :base_dir
6
+ attr_accessor :target
7
+ attr_accessor :classpath
8
+
9
+ def initialize(*args)
10
+ super
11
+ @classpath = []
12
+ enhance do |task|
13
+ test_cases.each do |test|
14
+ Dir.chdir base_dir
15
+ java "junit.textui.TestRunner", test, :classpath=>real_classpath, :name=>"tests in #{test}"
16
+ end
17
+ end
18
+ end
19
+
20
+ def test_cases()
21
+ target = File.expand_path(self.target)
22
+ return [] unless File.exist?(target)
23
+ prefix = Regexp.new("^" + Regexp.escape(target) + "/")
24
+ FileList[File.join(target, "**", "*Test.class")].
25
+ map { |path| path.sub(prefix, "").ext("").gsub(File::SEPARATOR, ".") }.sort
26
+ end
27
+
28
+ def real_classpath()
29
+ @real_classpath ||= artifacts(@classpath).map(&:to_s)
30
+ end
31
+
32
+ end
33
+
34
+ class Tests
35
+ def prepare(*tasks, &block)
36
+ returning(@prepare_task ||= task("prepare")) { |task| task.enhance tasks, &block }
37
+ end
38
+
39
+ def compile(*sources, &block)
40
+ unless @compile_task
41
+ @compile_task = Java::CompileTask.define_task("compile"=>prepare) { |task| resources.invoke }
42
+ end
43
+ returning(@compile_task) { |task| task.sources |= sources ; task.enhance &block }
44
+ end
45
+
46
+ def resources(*tasks, &block)
47
+ returning(@resources_task ||= Filter.define_task("resources")) { |task| task.enhance tasks, &block }
48
+ end
49
+
50
+ def junit(*tasks, &block)
51
+ unless @junit_task
52
+ @junit_task = JUnitTask.define_task("junit"=>compile)
53
+ end
54
+ returning(@junit_task) { |task| task.enhance tasks, &block }
55
+ end
56
+ end
57
+
58
+ class Project
59
+ inherited_attr :test_src_dir do File.join(src_dir, "test", "java") end
60
+ inherited_attr :test_resources_dir do File.join(src_dir, "test", "resources") end
61
+ inherited_attr :test_target_dir do File.join(target_dir, "test-classes") end
62
+
63
+ def tests()
64
+ @tests ||= Tests.new
65
+ end
66
+
67
+ def test(*tasks, &block)
68
+ @tests.junit *tasks, &block
69
+ end
70
+ end
71
+
72
+ # Global task compiles all projects.
73
+ desc "Run all test cases"
74
+ Project.local_task(task("test"))
75
+
76
+ Project.on_define do |project|
77
+ tests = nil
78
+ namespace "test" do
79
+ tests = project.tests
80
+ #tests.compile.enhance([tests.prepare]) { |task| tests.resources.invoke }
81
+ tests.compile.classpath += [ "junit:junit:jar:3.8.1", "jmock:jmock:jar:1.1.0" ]
82
+ tests.junit
83
+ end
84
+ tests.compile.enhance [ project.compile ]
85
+ project.recursive_task("test"=>project.test)
86
+
87
+ #project.recursive_task("compile")
88
+ #task("build").enhance [ project.compile ]
89
+ #task("clean") { rm_rf project.path_to(:target_dir), :verbose=>false }
90
+
91
+ project.enhance do |project|
92
+ tests.compile.sources << project.path_to(:test_src_dir) if File.exist?(project.path_to(:test_src_dir))
93
+ tests.compile.target ||= project.path_to(:test_target_dir)
94
+ tests.compile.classpath << project.compile.target
95
+ tests.resources.include project.path_to(:test_resources_dir, "*") if File.exists?(project.path_to(:test_resources_dir))
96
+ tests.resources.target ||= tests.compile.target
97
+ tests.junit.target = tests.compile.target
98
+ tests.junit.classpath += tests.compile.classpath
99
+ tests.junit.classpath += [ tests.compile.target, project.compile.target ]
100
+ tests.junit.base_dir = project.base_dir
101
+ file(tests.compile.target).enhance [ tests.compile ]
102
+ file(tests.resources.target).enhance [ tests.resources ]
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,66 @@
1
+ module Buildr
2
+
3
+ module XMLBeans
4
+
5
+ REQUIRES = [ "xmlbeans:xbean:jar:2.2.0", "stax:stax-api:jar:1.0" ]
6
+
7
+ def self.compile(*args)
8
+ options = Hash === args.last ? args.pop : {}
9
+ options[:verbose] ||= Rake.application.options.trace || false
10
+ fu_check_options options, :verbose, :noop, :javasource, :jar, :classes, :output
11
+
12
+ # Options for SchemaCompiler.
13
+ cmd_args = [ options[:verbose] ? "-verbose" : "-quiet" ]
14
+ cmd_args << "-javasource" << options[:javasource].collect.join(File::PATH_SEPARATOR) if options[:javasource]
15
+ cmd_args << "-out" << options[:jar] if options[:jar]
16
+ cmd_args << "-d" << options[:classes] if options[:classes]
17
+ cmd_args << "-src" << options[:output] if options[:output]
18
+ cmd_args += args
19
+ cmd_args << { :verbose=>options[:verbose] }
20
+
21
+ unless options[:noop]
22
+ verbose { puts "Running XMLBeans schema compiler" }
23
+ mkpath options[:classes], :verbose=>false rescue nil if options[:classes]
24
+ mkpath options[:output], :verbose=>false rescue nil if options[:output]
25
+ sh(Java.path_to_bin("java"), "-Xmx256m", "-cp", requires.join(File::PATH_SEPARATOR),
26
+ "org.apache.xmlbeans.impl.tool.SchemaCompiler", *cmd_args) { |ok, res|
27
+ fail "Failed to compile schemas, see errors above" unless ok }
28
+ # Touch paths to let other tasks know there's an update.
29
+ touch options[:classes], :verbose=>false if options[:classes]
30
+ touch options[:output], :verbose=>false if options[:output]
31
+ end
32
+ end
33
+
34
+ def self.requires()
35
+ @requires ||= artifacts(REQUIRES).each { |artifact| artifact.invoke }.map(&:to_s)
36
+ end
37
+
38
+ class CompileTask < Rake::FileTask
39
+
40
+ def initialize(*args)
41
+ super
42
+ enhance do |task|
43
+ XMLBeans.compile *task.prerequisites + [options.merge(:output=>task.name)]
44
+ end
45
+ end
46
+
47
+ def options()
48
+ @options ||= {}
49
+ end
50
+
51
+ def using(options)
52
+ self.options.merge!(options)
53
+ self
54
+ end
55
+
56
+ end
57
+
58
+ def self.compile_task(args)
59
+ output = args.keys.first
60
+ files = args.values.first.collect { |f| File.directory?(f) ? FileList[f + "/**/*"] : f }.flatten
61
+ CompileTask.define_task(output=>files)
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,38 @@
1
+ require "tempfile"
2
+
3
+ module Buildr
4
+
5
+ # Create a task that will download a file from a URL.
6
+ #
7
+ # Takes a single argument, a hash with one pair. The key is the file being
8
+ # created, the value if the URL to download. The task executes only if the
9
+ # file does not exist; the URL is not checked for updates.
10
+ #
11
+ # The task will show download progress on the console; if there are MD5/SHA1
12
+ # checksums on the server it will verify the download before saving it.
13
+ #
14
+ # For example:
15
+ # download "image.jpg"=>"http://example.com/theme/image.jpg"
16
+ def download(args)
17
+ if String === args || URI === args
18
+ # Given only a download URL, download into a temporary file.
19
+ # You can infer the file from task name.
20
+ temp = Tempfile.new(File.basename(args.to_s))
21
+ task = file_create(temp.path) do |task|
22
+ Transports.download task.source, task.name
23
+ end
24
+ task.sources << args
25
+ else
26
+ # Download to a file created by the task.
27
+ fail unless args.keys.size == 1
28
+ url = args.values.first
29
+ task = file_create(args.keys.first) do |task|
30
+ mkpath File.dirname(task.name), :verbose=>false
31
+ Transports.download task.source, task.name
32
+ end
33
+ task.sources << url
34
+ end
35
+ task
36
+ end
37
+
38
+ end