buildr 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,151 @@
1
+ 0.14 (2/28/2007)
2
+ * Added: check task that looks for obvious errors in the Rakefile.
3
+ * Added: deploy task for managing deployment.
4
+ * Added: release task that updates version numbers, commits and tags SVN.
5
+ * Changed: the project name is now the fully qualified name, e.g. ode:axis2
6
+ * Changed: you can now lookup a project before it's defined; you still can
7
+ only define a project once.
8
+ * Changed: you can lookup projects by full qualified name.
9
+ * Changed: release_to changed to deploy_to, which is now a getter/setter.
10
+ * Fixed: removed Java.home which conflicted with JRuby.
11
+ * Fixed: install task did not re-install modified files.
12
+ * Fixed: deploying only uploads one artifact.
13
+ * Fixed: timing issues.
14
+ * Fixed: Maven classifier now used properly.
15
+
16
+ 0.13 (2/26/2007)
17
+ * Added: global java method.
18
+ * Added: project build method.
19
+ * Added: OpenJPA mapping_tool method.
20
+ * Added: Rakefile to generate Gem.
21
+ * Changed: you can now lookup a sub-project from the top project method.
22
+ * Changed: the projects methods return all sub-projects.
23
+ * Fixed: bug in JarTask that resolved artifacts too early.
24
+ * Fixed: global tasks (clean, build, etc) now complain if executed from a directory
25
+ that does not map to any project.
26
+ * Fixed: to work with Rake 0.7.2.
27
+
28
+ 0.12 (2/24/2007)
29
+ * Added: call prepare with list of tasks to add them as prerequisites.
30
+ * Added: project.id returns the compound name, e.g. foo, foo-bar, foo-bar-baz.
31
+ * Added: JavaCC, XMLBeans schema compiler, OpenJPA enhancer, APT tasks.
32
+ * Changed: the default package ID is take from the project ID instead of its name.
33
+ * Changed: renamed buildr and moved here.
34
+ * Changed: moved all code into Buildr module.
35
+ * Fixed: download breaking when POM not found.
36
+ * Fixed: compile task fails if classpath is empty.
37
+ * Fixed: zip task fails if target directory does not exist.
38
+ * Fixed: packaging task does not require build.
39
+ * Fixed: compiler not showing command when trace is on.
40
+ * Fixed: zip dependencies were all fucked up.
41
+ * Fixed: package should not depend on build.
42
+
43
+ 0.11 (2/16/2007)
44
+ * Added: test cases for unzip task
45
+ * Added: prepare method to access prepare task
46
+ * Added: prepare, compile and resources accept a block you can use to enhance the task
47
+ * Changed: ZipTask executes all includes files as prerequisites, and now includes
48
+ directories correctly
49
+ * Changed: Jar/WarTask are now extended using with(options) method
50
+ * Changed: JarTask now accepts array of sections (each being a hash) for the manifest,
51
+ and a proc/method to generate it
52
+ * Changed: added HighLine to hide password entry on the command line
53
+ * Changed: unzip now using UnzipTask with its own shorthand syntax.
54
+ * Changed: filter task gets a consistent syntax to unzip
55
+
56
+ 0.10 (2/13/2007)
57
+ * Added: modifier for artifacts
58
+ * Added: ZipTask, WarTask
59
+ * Added: get POM artifact directly from artifact
60
+ * Changed: JAR and WAR packaging based on new and improved Zip task
61
+ * Changed: options for packaging, but not affecting current Rakefile
62
+ * Remove: delete task
63
+
64
+ 0.9 (2/9/2007)
65
+ * Added: attributes for configuring compile (sources, classpath, target, options)
66
+ * Added: shorthand notation for specifying compilation (to, with, using)
67
+ * Changed: copy task is dead (name conflict), instead we get the better filter
68
+ task with include/exclude patterns
69
+ * Changed: rewrite of compile task, now better than ever
70
+ * Changed: compile can be used inside and outside project
71
+ * Changed: compiler no longer infers anything from its prerequisites
72
+ * Changed: compiler accepts files, artifacts and tasks on the classpath
73
+ * Changed: resources task now working as expected
74
+ * Remove: global task artifacts was the root of all evil and got canned.
75
+
76
+ 0.8 (2/5/2007)
77
+ * Added: release task and release_to configuration for repositories
78
+ * Added: SFTP uploader for releases
79
+ * Added: convenience method group() for specifying multiple artifacts in same
80
+ group and version number
81
+ * Added: install target copies package to local repository and adds a POM,
82
+ uninstall package removes package (and POM) from local repository
83
+ * Changed: project lookup now happens through project() method
84
+ * Changed: locating file in the local repository now happens through Repositories
85
+ * Changed: downloading file into the local repository now happens through Repositories
86
+ * Changed: notation for specifying multiple artifacts in a string is now foo,bar,baz
87
+ * Changed: artifact identifier is now specified with the key :id
88
+ * Changed: download POM alongside artifact and install in local repository
89
+ * Changed: no more scoping artifacts collection in project, use compile.with instead
90
+ * Changed: moved HTTP download logic to transports.rb
91
+ * Removed: deprecated grouping with multiple artifacts under id key
92
+
93
+ 0.6 (2/1/2007)
94
+ * Added: Artifact resolution introduces the notion of a spec,
95
+ which can be supported using ActsAsArtifact
96
+ * Added: You can now use a project as an artifact, resulting in all its
97
+ packages being added, or use a task as artifact
98
+ * Changed: project.sub_projects renamed project.projects
99
+ * Changed: what used to be called dependencies is now called artifacts
100
+ * Changed: all artifacts are now created as tasks that know how to download
101
+ themselves unless some other behavior is specified
102
+ * Changed: local and remote repositories are now defined on the Rakefile
103
+ instead of individual projects
104
+ * Changed: attributes now stored directly as instance variables
105
+ * Changed: ANSI colors and progress bar now using Ruby Facets
106
+
107
+ 0.5 (1/24/2007)
108
+ * Added: Build number for each top-level project, build_number method for accessing
109
+ it and build:increment task for updating the build number file.
110
+ * Added: to_path method on project to resolve paths relative to base_dir.
111
+ * Added: recursive_task method on project to create task in project/sub-project.
112
+ * Added: compiler property for passing any options to Javac.
113
+ * Changed: remove task renamed uninstall.
114
+ * Changed: and to confuse more remove task (RemoveTask) renamed delete.
115
+ * Changed: consolidated before_create/after_create to on_create.
116
+ * Changed: version, group, artifact added as accessors to project.
117
+ * Changed: project definition block takes project as argument.
118
+ * Changed: project enhanced only if new settings or block.
119
+ * Changed: local_repository is now separate attribute from repositories.
120
+ * Changed: Directory structure, now split into rbs, rbs-java and tasks.
121
+ * Removed: project.options. Using a different attributes mechanism.
122
+
123
+ 0.4 (1/23/2007)
124
+ * Added: CopyTask now deals with files and directories, can copy multiple files,
125
+ and applies filter to all of them. Filter can be a hash or a proc.
126
+ * Added: Project gets resources_filter attribute that can be used to set the
127
+ filter on all copied resources.
128
+ * Added: HTTP module for getting and downloading files, and a download task.
129
+ * Changed: Dependencies now check signatures for every file, if available,
130
+ and show download progress.
131
+
132
+ 0.3 (1/22/2007)
133
+ * Added: Dependencies loaded from Maven repositories if not existing or built by project.
134
+ Use rake dependencies to force update, or let compilation take care of it.
135
+ * Added: Copy task for copying one file to another, and filtering support.
136
+
137
+ 0.2 (1/21/2007)
138
+ * Added: remove task to get rid of packages added to the local repository.
139
+ * Changed: recompile project if any of its dependencies is newer than the source code.
140
+ Will cause recompile if any of the dependencies was compiled and packaged again.
141
+ * Changed: compile task depends on javac task and resource copy tasks.
142
+ This might change when adding filtering later on.
143
+
144
+ 0.1 (1/19/2007)
145
+ * Added: build and clean tasks
146
+ * Added: resources are now copied over during compilation
147
+ * Added: POM file generated in local repository (keep Maven happy)
148
+ * Added: compile scope for use by javac
149
+ * Added: WAR packaging.
150
+ * Changed: Root project operates on the current directory, sub-projects on sub
151
+ directories. See Rakefile for example.
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2006, Intalio Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README ADDED
File without changes
data/lib/buildr.rb ADDED
@@ -0,0 +1,43 @@
1
+ # Remember that all these need to be Gem dependencies.
2
+ gem "facets"
3
+ gem "builder"
4
+ gem "net-ssh"
5
+ gem "net-sftp"
6
+ gem "rubyzip"
7
+ gem "highline"
8
+
9
+ module Buildr
10
+ VERSION = "0.14.0"
11
+ end
12
+
13
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__))
14
+ require "core/core.rb"
15
+ require "core/project.rb"
16
+ require "core/artifact.rb"
17
+ require "core/build.rb"
18
+ require "core/transports.rb"
19
+
20
+ require "tasks/download"
21
+ require "tasks/filter"
22
+ require "tasks/zip"
23
+
24
+ require "java/java"
25
+ require "java/compile"
26
+ require "java/javacc"
27
+ require "java/openjpa"
28
+ require "java/packaging"
29
+ require "java/xmlbeans"
30
+
31
+ include Buildr
32
+
33
+ # The greate method_missing/Object extend bug requires us to load
34
+ # XMLBuilder after we're done enhancing Object.
35
+ require "builder"
36
+
37
+ # Load the settings files.
38
+ if File.exist?(File.join(ENV["HOME"], "buildr.rb"))
39
+ load File.join(ENV["HOME"], "buildr.rb")
40
+ end
41
+ if File.exist?(File.join(Rake.application.original_dir, "buildr.rb"))
42
+ load File.join(Rake.application.original_dir, "buildr.rb")
43
+ end
@@ -0,0 +1,394 @@
1
+ module Buildr
2
+
3
+ # This module gives you a way to access the individual properties of an
4
+ # artifact: id, group, type and version. It can also return the artifact
5
+ # specification.
6
+ module ActsAsArtifact
7
+
8
+ class << self
9
+ def included(mod)
10
+ mod.extend self
11
+ end
12
+ end
13
+
14
+ # The artifact id.
15
+ attr_reader :id
16
+ # The group id.
17
+ attr_reader :group
18
+ # The file type.
19
+ attr_reader :type
20
+ # The version number.
21
+ attr_reader :version
22
+ # Optional classifier.
23
+ attr_reader :classifier
24
+
25
+ # Returns the artifact specification as a hash.
26
+ def to_spec_hash()
27
+ base = { :group=>group, :id=>id, :type=>type, :version=>version }
28
+ classifier.blank? ? base : base.merge(:classifier=>classifier)
29
+ end
30
+ alias_method :to_hash, :to_spec_hash
31
+
32
+ # Returns the artifact specification, in the structure:
33
+ # <group>:<artifact>:<type>:<version>
34
+ def to_spec()
35
+ classifier.blank? ? "#{group}:#{id}:#{type}:#{version}" : "#{group}:#{id}:#{type}:#{classifier}:#{version}"
36
+ end
37
+
38
+ # Apply specification to this artifact.
39
+ def apply_spec(spec)
40
+ case spec
41
+ when String
42
+ @group, @id, @type, @version, *rest = spec.split(":")
43
+ unless rest.empty?
44
+ @classifier, @version = @version, rest.shift
45
+ fail "Expecting project:id:type:version or project:id:type:classifier:version, found #{spec}" unless rest.empty?
46
+ end
47
+ when Hash
48
+ [:group, :id, :type, :version, :classifier].each { |key| instance_variable_set("@#{key}", spec[key]) }
49
+ @type ||= DEFAULT_FILE_TYPE
50
+ else
51
+ raise ArgumentError, "Expecting a string or a hash"
52
+ end
53
+ self
54
+ end
55
+
56
+ def pom()
57
+ return self if type.to_s == "pom"
58
+ artifact(:group=>group, :id=>id, :version=>version, :type=>"pom", :classifier=>classifier)
59
+ end
60
+
61
+ end
62
+
63
+
64
+ # Use the artifact and artifacts method to create artifact tasks.
65
+ class Artifact < Rake::FileCreationTask
66
+
67
+ # The default file type for artifacts, if not specified.
68
+ DEFAULT_FILE_TYPE = "jar"
69
+
70
+ include ActsAsArtifact
71
+
72
+ class << self
73
+
74
+ # Lookup an artifact task based on its specification.
75
+ def lookup(spec)
76
+ @artifacts ||= {}
77
+ @artifacts[hash_to_spec(spec)]
78
+ end
79
+
80
+ # Register a task as an artifact. Returns the task when calling
81
+ # #artifacts. For example, a project will use this to register the
82
+ # packages it creates.
83
+ def register(task)
84
+ @artifacts ||= {}
85
+ if task.respond_to?(:to_hash)
86
+ @artifacts[hash_to_spec(task.to_hash)] = task
87
+ else
88
+ fail "Can only call with an artifact task"
89
+ end
90
+ end
91
+
92
+ # Turn a spec into a hash. This method accepts a string, hash or any object
93
+ # that responds to the method to_spec. There are several reasons you'll want
94
+ # to use this method:
95
+ # * You can pass it anything that could possibly be a spec, and get a hash.
96
+ # * It will check that your spec includes the group identifier, artifact
97
+ # identifier and version number, and set the file type, if not specified.
98
+ # * It will always return a new specs hash.
99
+ # * Calling to_s on the hash will return a spec string.
100
+ #
101
+ # :nodoc:
102
+ def spec_to_hash(spec)
103
+ return spec_to_hash(spec.to_spec) if spec.respond_to?(:to_spec)
104
+ if String === spec
105
+ group, id, type, version, *rest = spec.split(":")
106
+ unless rest.empty?
107
+ classifier, version = version, rest.shift
108
+ fail "Expecting project:id:type:version or project:id:type:classifier:version, found #{spec}" unless rest.empty?
109
+ end
110
+ fail "Missing file type for #{spec}" if type.blank?
111
+ spec_to_hash :group=>group, :id=>id, :type=>type, :version=>version, :classifier=>classifier
112
+ elsif Hash === spec
113
+ spec = spec.clone
114
+ fail "Missing group identifier for #{spec.inspect}" if spec[:group].blank?
115
+ fail "Missing artifact identifier for #{spec.inspect}" if spec[:id].blank?
116
+ fail "Missing version for #{spec.inspect}" if spec[:version].blank?
117
+ spec[:type] = DEFAULT_FILE_TYPE if spec[:type].blank?
118
+ spec
119
+ else
120
+ fail "Spec must be a string, hash or object that responds to to_spec"
121
+ end
122
+ end
123
+
124
+ # Convert a hash back to a spec string.
125
+ def hash_to_spec(hash)
126
+ version = ":#{hash[:version]}" unless hash[:version].blank?
127
+ classifier = ":#{hash[:classifier]}" unless hash[:classifier].blank?
128
+ "#{hash[:group]}:#{hash[:id]}:#{hash[:type] || DEFAULT_FILE_TYPE}#{classifier}#{version}"
129
+ end
130
+
131
+ # Convert a hash to a file name.
132
+ def hash_to_file_name(hash)
133
+ version = "-#{hash[:version]}" unless hash[:version].blank?
134
+ classifier = "-#{hash[:classifier]}" unless hash[:classifier].blank?
135
+ "#{hash[:id]}#{version}#{classifier}.#{hash[:type] || DEFAULT_FILE_TYPE}"
136
+ end
137
+
138
+ end
139
+
140
+ def initialize(*args)
141
+ super
142
+ enhance do |task|
143
+ # Download the artifact form one of the remote repositories if the
144
+ # file does not exist in the local repository, and no other behavior
145
+ # specified. If this task has been enhanced, delegate to the other
146
+ # enhancers. We don't know if this is the first or other enhancement,
147
+ # but we only need to know it's not the only one.
148
+ if @actions.size == 1
149
+ repositories.download(to_spec)
150
+ end
151
+ end
152
+ end
153
+
154
+ end
155
+
156
+
157
+ # Singleton object for specifying the local, remote and release repositories.
158
+ class Repositories
159
+ include Singleton
160
+
161
+ # Returns the path to the local repository.
162
+ #
163
+ # The default path is .m2/repository relative to the home directory.
164
+ def local()
165
+ @local ||= ENV["local_repo"] || File.join(ENV["HOME"], ".m2", "repository")
166
+ end
167
+
168
+ # Sets the path to the local repository.
169
+ def local=(dir)
170
+ @local = dir ? File.expand_path(dir) : nil
171
+ end
172
+
173
+ # Locates an artifact in the local repository based on its specification.
174
+ #
175
+ # For example:
176
+ # locate :group=>"log4j", :id=>"log4j", :version=>"1.1"
177
+ # => ~/.m2/repository/log4j/log4j/1.1/log4j-1.1.jar
178
+ def locate(spec)
179
+ spec = Artifact.spec_to_hash(spec) unless Hash === spec
180
+ File.join(local, spec[:group].split("."), spec[:id], spec[:version], Artifact.hash_to_file_name(spec))
181
+ end
182
+
183
+ # Returns a hash of all the remote repositories. The key is the repository
184
+ # identifier, and the value is the repository base URL.
185
+ def remote()
186
+ @remote ||= {}
187
+ end
188
+
189
+ # Sets the remote repositories from a hash. See #remote.
190
+ def remote=(hash)
191
+ case hash
192
+ when nil
193
+ @remote = {}
194
+ when Hash
195
+ @remote = hash.clone
196
+ else
197
+ raise ArgumentError, "Expecting a hash" unless Hash === hash
198
+ end
199
+ end
200
+
201
+ # Adds more remote repositories from a hash. See #remote.
202
+ #
203
+ # For example:
204
+ # repositories.remote.add :ibiblio=>"http://www.ibiblio.org/maven2"
205
+ def add(hash)
206
+ remote.merge!(hash)
207
+ end
208
+
209
+ # Attempts to download the artifact from one of the remote repositories
210
+ # and store it in the local repository. Returns the path if downloaded,
211
+ # otherwise raises an exception.
212
+ def download(spec)
213
+ spec = Artifact.spec_to_hash(spec) unless Hash === spec
214
+ path = locate(spec)
215
+
216
+ puts "Downloading #{Artifact.hash_to_spec(spec)}" if Rake.application.options.trace
217
+ return path if remote.any? do |repo_id, repo_url|
218
+ begin
219
+ rel_path = spec[:group].gsub(".", "/") +
220
+ "/#{spec[:id]}/#{spec[:version]}/#{Artifact.hash_to_file_name(spec)}"
221
+ Transports.perform URI.parse(repo_url.to_s) do |http|
222
+ mkpath File.dirname(path), :verbose=>false
223
+ http.download(rel_path, path)
224
+ begin
225
+ http.download(rel_path.ext("pom"), path.ext("pom"))
226
+ rescue Transports::NotFound
227
+ end
228
+ end
229
+ true
230
+ rescue Exception=>error
231
+ warn error if Rake.application.options.trace
232
+ false
233
+ end
234
+ end
235
+ fail "Failed to download #{Artifact.hash_to_spec(spec)}, tried the following repositories:\n#{repositories.remote.values.join("\n")}"
236
+ end
237
+
238
+ # Specifies deployment target for all artifacts generated by this project.
239
+ #
240
+ # For example:
241
+ # repositories.deploy_to = "sftp://example.com/var/www/maven/"
242
+ # or:
243
+ # repositories.deploy_to = "sftp://john:secret@example.com/var/www/maven/"
244
+ def deploy_to=(options)
245
+ options = { :url=>options } unless Hash === options
246
+ @deploy_to = options
247
+ end
248
+
249
+ def deploy_to()
250
+ @deploy_to || {}
251
+ end
252
+
253
+ end
254
+
255
+ # Returns a global object for setting local and remote repositories.
256
+ # See Repositories.
257
+ def repositories()
258
+ Repositories.instance
259
+ end
260
+
261
+ # Creates a file task to download and install the specified artifact.
262
+ #
263
+ # The artifact specification can be a string or a hash.
264
+ # The file task points to the artifact in the local repository.
265
+ #
266
+ # You can provide alternative behavior to create the artifact instead
267
+ # of downloading it from a remote repository.
268
+ #
269
+ # For example, to specify an artifact:
270
+ # artifact("log4j:log4j:jar:1.1")
271
+ #
272
+ # To use the artifact in a task:
273
+ # unzip artifact("org.apache.pxe:db-derby:zip:1.2")
274
+ #
275
+ # To specify an artifact and the means for creating it:
276
+ # download(artifact("dojo:dojo-widget:zip:2.0")=>
277
+ # "http://download.dojotoolkit.org/release-2.0/dojo-2.0-widget.zip")
278
+ def artifact(spec, &block)
279
+ spec = Artifact.spec_to_hash(spec)
280
+ unless task = Artifact.lookup(spec)
281
+ task = Artifact.define_task(repositories.locate(spec))
282
+ Artifact.register(task)
283
+ end
284
+ task.apply_spec spec
285
+ task.enhance(&block) if block_given?
286
+ task
287
+ end
288
+
289
+ # Creates multiple artifacts from a set of specifications and returns
290
+ # an array of tasks.
291
+ #
292
+ # You can pass any number of arguments, each of which can be:
293
+ # * An artifact specification, string or hash. Returns a new task for
294
+ # each specification, by calling #artifact.
295
+ # * An artifact task or any other task. Returns the task as is.
296
+ # * A project. Returns all packaging tasks in that project.
297
+ # * An array of artifacts. Returns all the artifacts found there.
298
+ #
299
+ # This method handles arrays of artifacts as if they are flattend,
300
+ # to help in managing large combinations of artifacts. For example:
301
+ # xml = [ xerces, xalan, jaxp ]
302
+ # ws = [ axis, jax-ws, jaxb ]
303
+ # db = [ jpa, mysql, sqltools ]
304
+ # base = [ xml, ws, db ]
305
+ # artifacts(base, models, services)
306
+ #
307
+ # You can also pass tasks and project. This is particularly useful for
308
+ # dealing with dependencies between projects that are part of the same
309
+ # build.
310
+ #
311
+ # For example:
312
+ # artifacts(base, models, services, module1, module2)
313
+ #
314
+ # When passing a project as argument, it expands that project to all
315
+ # its packaging tasks. You can then use the resulting artifacts as
316
+ # dependencies that will force these packages to be build inside the
317
+ # project, without installing them in the local repository.
318
+ def artifacts(*specs)
319
+ specs.inject([]) do |set, spec|
320
+ case spec
321
+ when Hash
322
+ set |= [artifact(spec)]
323
+ when /:.*:.*:/
324
+ set |= [artifact(spec)]
325
+ when String
326
+ set |= [file(spec)]
327
+ when Rake::Task
328
+ set |= [spec]
329
+ when Project
330
+ set |= artifacts(spec.packages)
331
+ when Array
332
+ set |= artifacts(*spec)
333
+ else
334
+ fail "Invalid artifact specification: #{spec || 'nil'}"
335
+ end
336
+ set
337
+ end
338
+ end
339
+
340
+ # Convenience method for defining multiple artifacts that belong
341
+ # to the same version and group. Accepts multiple artifact identifiers
342
+ # (or arrays of) followed by two has keys:
343
+ # * :under -- The group identifier
344
+ # * :version -- The version number
345
+ #
346
+ # For example:
347
+ # group "xbean", "xbean_xpath", "xmlpublic", :under=>"xmlbeans", :version=>"2.1.0"
348
+ # Or:
349
+ # group %w{xbean xbean_xpath xmlpublic}, :under=>"xmlbeans", :version=>"2.1.0"
350
+ def group(*args)
351
+ hash = args.pop
352
+ args.flatten.map { |id| artifact :group=>hash[:under], :version=>hash[:version], :id=>id }
353
+ end
354
+
355
+ # Creates and return a task that will deploy all the specified
356
+ # artifacts and files. Specify the deployment server by passing it
357
+ # as the last argument (must be a hash).
358
+ #
359
+ # For example:
360
+ # deploy(*process.packages, :url=>"sftp://example.com/var/www/maven")
361
+ def deploy(*args)
362
+ # Where do we release to?
363
+ if Hash === args.last
364
+ options = args.pop
365
+ else
366
+ options = repositories.deploy_to
367
+ options = { :url=>options.to_s } unless Hash === options
368
+ end
369
+ url = options[:url]
370
+ options = options.reject { |k,v| k === :url }
371
+ fail "Don't know where to release, specify a URL or use repositories.deploy_to = url|hash" if url.blank?
372
+
373
+ # Arguments are artifacts and types so we depend on them.
374
+ task(url=>args).enhance do |task|
375
+ Transports.perform url, options do |session|
376
+ args.each do |artifact|
377
+ if artifact.respond_to?(:to_spec)
378
+ # Upload artifact relative to base URL, need to create path before uploading.
379
+ puts "Deploying #{artifact.to_spec}" if verbose
380
+ spec = artifact.to_spec_hash
381
+ path = spec[:group].gsub(".", "/") + "/#{spec[:id]}/#{spec[:version]}/"
382
+ session.mkpath path
383
+ session.upload artifact.to_s, path + Artifact.hash_to_file_name(spec)
384
+ else
385
+ # Upload artifact to URL.
386
+ puts "Deploying #{artifact}" if verbose
387
+ session.upload artifact, File.basename(artifact)
388
+ end
389
+ end
390
+ end
391
+ end
392
+ end
393
+
394
+ end