buildr4osgi 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/LICENSE +176 -0
  2. data/NOTICE +6 -0
  3. data/README.rdoc +50 -0
  4. data/Rakefile +45 -0
  5. data/buildr4osgi.gemspec +40 -0
  6. data/lib/buildr4osgi/compile/compiler.rb +54 -0
  7. data/lib/buildr4osgi/compile/ecj-3.4.1.jar +0 -0
  8. data/lib/buildr4osgi/compile.rb +16 -0
  9. data/lib/buildr4osgi/eclipse/feature.rb +271 -0
  10. data/lib/buildr4osgi/eclipse/plugin.rb +22 -0
  11. data/lib/buildr4osgi/eclipse.rb +17 -0
  12. data/lib/buildr4osgi/nature/eclipse.rb +80 -0
  13. data/lib/buildr4osgi/nature/java.rb +32 -0
  14. data/lib/buildr4osgi/nature/nature.rb +156 -0
  15. data/lib/buildr4osgi/nature/osgi.rb +32 -0
  16. data/lib/buildr4osgi/nature/scala.rb +32 -0
  17. data/lib/buildr4osgi/nature.rb +23 -0
  18. data/lib/buildr4osgi/osgi/bundle.rb +275 -0
  19. data/lib/buildr4osgi/osgi/bundle_package.rb +80 -0
  20. data/lib/buildr4osgi/osgi/container.rb +140 -0
  21. data/lib/buildr4osgi/osgi/library_extension.rb +174 -0
  22. data/lib/buildr4osgi/osgi/packaging.rb +129 -0
  23. data/lib/buildr4osgi/osgi/project_extension.rb +324 -0
  24. data/lib/buildr4osgi/osgi/registry.rb +61 -0
  25. data/lib/buildr4osgi/osgi/resolving_strategies.rb +104 -0
  26. data/lib/buildr4osgi/osgi/version.rb +131 -0
  27. data/lib/buildr4osgi/osgi.rb +24 -0
  28. data/lib/buildr4osgi.rb +37 -0
  29. data/rakelib/checks.rake +57 -0
  30. data/rakelib/doc.rake +92 -0
  31. data/rakelib/jekylltask.rb +120 -0
  32. data/rakelib/package.rake +73 -0
  33. data/rakelib/release.rake +149 -0
  34. data/rakelib/rspec.rake +73 -0
  35. data/rakelib/setup.rake +54 -0
  36. data/rakelib/stage.rake +206 -0
  37. data/spec/compile/compiler_spec.rb +30 -0
  38. data/spec/eclipse/feature_spec.rb +295 -0
  39. data/spec/nature/eclipse_spec.rb +46 -0
  40. data/spec/nature/java_spec.rb +45 -0
  41. data/spec/nature/osgi_spec.rb +63 -0
  42. data/spec/nature/scala_spec.rb +45 -0
  43. data/spec/nature_spec.rb +144 -0
  44. data/spec/osgi/bundle_package_spec.rb +32 -0
  45. data/spec/osgi/bundle_spec.rb +202 -0
  46. data/spec/osgi/container_spec.rb +93 -0
  47. data/spec/osgi/library_extension_spec.rb +142 -0
  48. data/spec/osgi/packaging_spec.rb +340 -0
  49. data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/META-INF/ECLIPSEF.RSA +0 -0
  50. data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/META-INF/ECLIPSEF.SF +20 -0
  51. data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/META-INF/MANIFEST.MF +28 -0
  52. data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/META-INF/eclipse.inf +3 -0
  53. data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/about.html +28 -0
  54. data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/fragment.properties +12 -0
  55. data/spec/osgi/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20090429-1800/runtime_registry_compatibility.jar +0 -0
  56. data/spec/osgi/project_extension_spec.rb +662 -0
  57. data/spec/osgi/registry_spec.rb +50 -0
  58. data/spec/osgi/version_spec.rb +127 -0
  59. data/spec/spec_helpers.rb +85 -0
  60. data/spec/tmp/remote/eclipse/org.eclipse.debug.ui/3.4.1.v20080811_r341/org.eclipse.debug.ui-3.4.1.v20080811_r341.jar +0 -0
  61. data/spec/tmp/remote/eclipse/org.eclipse.debug.ui/3.4.1.v20080811_r341/org.eclipse.debug.ui-3.4.1.v20080811_r341.pom +82 -0
  62. data/spec/tmp/remote/org/slf4j/jcl104-over-slf4j/1.5.8/jcl104-over-slf4j-1.5.8-sources.jar +0 -0
  63. data/spec/tmp/remote/org/slf4j/jcl104-over-slf4j/1.5.8/jcl104-over-slf4j-1.5.8.jar +0 -0
  64. data/spec/tmp/remote/org/slf4j/jcl104-over-slf4j/1.5.8/jcl104-over-slf4j-1.5.8.pom +30 -0
  65. data/spec/tmp/remote/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8-sources.jar +0 -0
  66. data/spec/tmp/remote/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.jar +0 -0
  67. data/spec/tmp/remote/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.pom +101 -0
  68. data/spec/tmp/remote/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8-sources.jar +0 -0
  69. data/spec/tmp/remote/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8.jar +0 -0
  70. data/spec/tmp/remote/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8.pom +56 -0
  71. metadata +142 -0
@@ -0,0 +1,324 @@
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
+ # Methods added to Project for compiling, handling of resources and generating source documentation.
17
+ module OSGi
18
+
19
+ module BundleCollector #:nodoc:
20
+
21
+ attr_accessor :bundles, :projects, :project_dependencies
22
+
23
+ # Collects the bundles associated with a project.
24
+ # Returns them as a sorted array.
25
+ #
26
+ def collect(project)
27
+ @bundles = []
28
+ @projects = []
29
+ project.manifest_dependencies().each {|dep| _collect(dep, project)}
30
+ end
31
+
32
+ # Collects the bundles associated with the bundle
33
+ #
34
+ def _collect(bundle, project)
35
+ if bundle.is_a?(Bundle)
36
+ bundle = bundle.resolve(project)
37
+ unless bundle.nil?
38
+ if bundle.is_a?(Buildr::Project)
39
+ @projects << bundle
40
+ elsif !(@bundles.include? bundle)
41
+ @bundles << bundle
42
+ @bundles |= bundle.fragments(project)
43
+ (bundle.bundles + bundle.imports).each {|b|
44
+ _collect(b, project)
45
+ }
46
+ end
47
+ end
48
+ elsif bundle.is_a?(BundlePackage)
49
+ bundle.resolve(project).each {|b|
50
+ if b.is_a?(Buildr::Project)
51
+ @projects << b
52
+ elsif !(@bundles.include? b)
53
+ @bundles << b
54
+ (b.bundles + b.imports).each {|import|
55
+ _collect(import, project)
56
+ }
57
+ end
58
+ }
59
+ elsif bundle.is_a?(Buildr::Project)
60
+ @projects << bundle
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ class DependenciesTask < Rake::Task #:nodoc:
67
+ include BundleCollector
68
+ attr_accessor :project
69
+
70
+ def initialize(*args) #:nodoc:
71
+ super
72
+
73
+ enhance do |task|
74
+ _dependencies = {}
75
+ _projects = {}
76
+ project.projects.each do |subp|
77
+ collect(subp)
78
+ _projects[subp.name] = projects.collect {|p| p.name}.uniq.sort
79
+ _dependencies[subp.name] = bundles.sort
80
+ end
81
+
82
+ collect(project)
83
+ _dependencies[project.name] = bundles.sort
84
+ _projects[project.name] = projects.collect {|p| p.name}.uniq.sort
85
+
86
+ def find_root(project)
87
+ project.parent.nil? ? project : project.parent
88
+ end
89
+
90
+ base_dir = find_root(project).base_dir
91
+ written_dependencies = YAML.load(File.read(File.join(base_dir, "dependencies.yml"))) if File.exists? File.join(base_dir, "dependencies.yml")
92
+ written_dependencies ||= {}
93
+ written_dependencies.extend SortedHash
94
+
95
+
96
+ _projects.keys.each {|p|
97
+ written_dependencies[p] ||= {}
98
+ written_dependencies[p].extend SortedHash
99
+ written_dependencies[p]["dependencies"] ||= []
100
+ written_dependencies[p]["projects"] ||= []
101
+ written_dependencies[p]["dependencies"] |= _dependencies[p]
102
+ written_dependencies[p]["projects"] |= _projects[p]
103
+ written_dependencies[p]["dependencies"].sort!
104
+ written_dependencies[p]["projects"].sort!
105
+ }
106
+
107
+ Buildr::write File.join(base_dir, "dependencies.yml"), written_dependencies.to_yaml
108
+ end
109
+ end
110
+ end
111
+
112
+ class InstallTask < Rake::Task #:nodoc:
113
+ include BundleCollector
114
+ attr_accessor :project, :local
115
+
116
+ def initialize(*args) #:nodoc:
117
+ super
118
+
119
+ enhance do |task|
120
+ dependencies = []
121
+ project.projects.each do |subp|
122
+ collect(subp)
123
+ dependencies |= bundles
124
+ end
125
+ collect(project)
126
+ dependencies |= bundles
127
+ dependencies.flatten.uniq.sort.each {|bundle|
128
+
129
+ begin
130
+ if File.directory?(bundle.file)
131
+ begin
132
+
133
+ tmp = File.join(Dir::tmpdir, File.basename(bundle.file))
134
+ rm tmp if File.exists? tmp
135
+ base = Pathname.new(bundle.file)
136
+ Zip::ZipFile.open(tmp, Zip::ZipFile::CREATE) {|zipfile|
137
+ Dir.glob("#{bundle.file}/**/**").each do |file|
138
+ if(file.match(/.*\.jar/)) #unpack the jars in the directory so its contents are readable by all Java compilers.
139
+ Zip::ZipFile.open(file) do |source|
140
+ source.entries.reject { |entry| entry.directory? }.each do |entry|
141
+ zipfile.get_output_stream(entry.name) {|output| output.write source.read(entry.name)}
142
+ end
143
+ end
144
+ else
145
+ zipfile.add(Pathname.new(file).relative_path_from(base), file)
146
+ end
147
+ end
148
+ }
149
+ bundle.file = tmp
150
+
151
+ rescue Exception => e
152
+ error e.message
153
+ trace e.backtrace.join("\n")
154
+ end
155
+
156
+ end
157
+
158
+ if local
159
+ artifact = Buildr::artifact(bundle.to_s)
160
+ installed = Buildr.repositories.locate(artifact)
161
+ mkpath File.dirname(installed)
162
+ Buildr::artifact(bundle.to_s).from(bundle.file).install
163
+ info "Installed #{installed}"
164
+ else
165
+ Buildr::artifact(bundle.to_s).from(bundle.file).upload
166
+ info "Uploaded #{bundle}"
167
+ end
168
+ rescue Exception => e
169
+ error "Error installing the artifact #{bundle.to_s}"
170
+ trace e.message
171
+ trace e.backtrace.join("\n")
172
+ end
173
+ }
174
+ end
175
+ end
176
+ end
177
+
178
+ module ProjectExtension #:nodoc:
179
+ include Extension
180
+
181
+ first_time do
182
+ desc 'Evaluate OSGi dependencies and places them in dependencies.yml'
183
+ Project.local_task('osgi:resolve:dependencies') { |name| "Resolve dependencies for #{name}" }
184
+ desc 'Installs OSGi dependencies in the Maven local repository'
185
+ Project.local_task('osgi:install:dependencies') { |name| "Install dependencies for #{name}" }
186
+ desc 'Installs OSGi dependencies in the Maven local repository'
187
+ Project.local_task('osgi:upload:dependencies') { |name| "Upload dependencies for #{name}" }
188
+ desc 'Cleans the dependencies.yml file'
189
+ Project.local_task('osgi:clean:dependencies') {|name| "Clean dependencies for #{name}"}
190
+ end
191
+
192
+ before_define do |project|
193
+ dependencies = DependenciesTask.define_task('osgi:resolve:dependencies')
194
+ dependencies.project = project
195
+ install = InstallTask.define_task('osgi:install:dependencies')
196
+ install.project = project
197
+ install.local = true
198
+ upload = InstallTask.define_task('osgi:upload:dependencies')
199
+ upload.project = project
200
+
201
+
202
+ clean = Rake::Task.define_task('osgi:clean:dependencies').enhance do
203
+ Buildr::write File.join(project.base_dir, "dependencies.yml"),
204
+ project.projects.inject({}) {|hash, p| hash.merge({p.name => []})}.merge({project.name => []}).to_yaml
205
+ end
206
+ install.project = project
207
+ end
208
+
209
+ #
210
+ #
211
+ # Reads the dependencies from dependencies.yml
212
+ # and returns the direct dependencies of the project, as well as its project dependencies and their own dependencies.
213
+ # This method is used recursively, so beware of cyclic dependencies.
214
+ #
215
+ def dependencies(&block)
216
+
217
+ deps = Dependencies.new
218
+ deps.read(project)
219
+ return deps.projects + deps.dependencies
220
+ end
221
+
222
+ class OSGi #:nodoc:
223
+
224
+ attr_reader :options, :registry
225
+
226
+ def initialize(project)
227
+ if (project.parent)
228
+ @options = project.parent.osgi.options.dup
229
+ @registry = project.parent.osgi.registry.dup
230
+ end
231
+ @options ||= Options.new
232
+ @registry ||= ::OSGi::Registry.new
233
+ end
234
+
235
+ # The options for the osgi.options method
236
+ # package_resolving_strategy:
237
+ # The package resolving strategy, it should be a symbol representing a module function in the OSGi::PackageResolvingStrategies module.
238
+ # bundle_resolving_strategy:
239
+ # The bundle resolving strategy, it should be a symbol representing a module function in the OSGi::BundleResolvingStrategies module.
240
+ class Options
241
+ attr_accessor :package_resolving_strategy, :bundle_resolving_strategy
242
+
243
+ def initialize
244
+ @package_resolving_strategy = :all
245
+ @bundle_resolving_strategy = :latest
246
+ end
247
+
248
+ end
249
+ end
250
+
251
+ # Makes a osgi instance available to the project.
252
+ # The osgi object may be used to access OSGi containers
253
+ # or set options, currently the resolving strategies.
254
+ def osgi
255
+ @osgi ||= OSGi.new(self)
256
+ @osgi
257
+ end
258
+
259
+ # returns an array of the dependencies of the plugin, read from the manifest.
260
+ def manifest_dependencies()
261
+ as_bundle = Bundle.fromProject(self)
262
+ as_bundle.nil? ? [] : as_bundle.bundles.collect{|b| b.resolve(self)}.compact + as_bundle.imports.collect {|i| i.resolve(self)}.flatten
263
+ end
264
+
265
+ end
266
+
267
+ private
268
+
269
+ #
270
+ # A class to read dependencies.yml, and get a flat array of projects and dependencies for a project.
271
+ class Dependencies
272
+
273
+ attr_accessor :dependencies, :projects
274
+
275
+ def read(project)
276
+ def find_root(project)
277
+ project.parent.nil? ? project : project.parent
278
+ end
279
+
280
+ base_dir = find_root(project).base_dir
281
+ @dependencies = []
282
+ @projects = []
283
+ @deps_yml = {}
284
+ return unless File.exists? File.join(base_dir, "dependencies.yml")
285
+ @deps_yml =YAML.load(File.read(File.join(base_dir, "dependencies.yml")))
286
+ return if @deps_yml[project.name].nil? || @deps_yml[project.name]["dependencies"].nil?
287
+ _read(project.name, false)
288
+ @dependencies = @dependencies.flatten.compact.uniq
289
+ return @dependencies, @projects
290
+ end
291
+
292
+ private
293
+
294
+ def _read(project, add_project = true)
295
+ @dependencies |= @deps_yml[project]["dependencies"]
296
+ projects << Buildr::project(project) if add_project
297
+ @deps_yml[project]["projects"].each {|p| _read(p) unless projects.include?(p)}
298
+ end
299
+ end
300
+
301
+ # Copy/pasted from here: http://snippets.dzone.com/posts/show/5811
302
+ # no author information though.
303
+ module SortedHash
304
+
305
+ # Replacing the to_yaml function so it'll serialize hashes sorted (by their keys)
306
+ #
307
+ # Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb
308
+ def to_yaml( opts = {} )
309
+ YAML::quick_emit( object_id, opts ) do |out|
310
+ out.map( taguri, to_yaml_style ) do |map|
311
+ sort.each do |k, v| # <-- here's my addition (the 'sort')
312
+ map.add( k, v )
313
+ end
314
+ end
315
+ end
316
+ end
317
+ end
318
+ end
319
+
320
+ module Buildr #:nodoc:
321
+ class Project #:nodoc:
322
+ include OSGi::ProjectExtension
323
+ end
324
+ end
@@ -0,0 +1,61 @@
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 OSGi
17
+
18
+ #
19
+ # A class to hold the registered containers. It is possible to add containers until resolved_containers is called,
20
+ # after which it is not possible to modify the registry anymore.
21
+ #
22
+ class Registry
23
+
24
+ #
25
+ # Sets the containers of the registry
26
+ # Raises an exception if containers have been resolved already.
27
+ #
28
+ def containers=(containers)
29
+ raise "Cannot set containers, containers have been resolved already" if @resolved_containers
30
+ @containers = containers
31
+ end
32
+
33
+ #
34
+ # Returns the containers associated with this registry.
35
+ # The list of containers is modifiable if resolved_containers hasn't been called yet.
36
+ #
37
+ def containers
38
+ unless @containers
39
+ @containers = [Buildr.settings.user, Buildr.settings.build].inject([]) { |repos, hash|
40
+ repos | Array(hash['osgi'] && hash['osgi']['containers'])
41
+ }
42
+ if ENV['OSGi']
43
+ @containers |= ENV['OSGi'].split(';')
44
+ end
45
+ end
46
+ @resolved_containers.nil? ? @containers : @containers.dup.freeze
47
+ end
48
+
49
+ #
50
+ # Resolves the containers registered in this registry.
51
+ # This is a long running operation where all the containers are parsed.
52
+ #
53
+ # Containers are resolved only once.
54
+ #
55
+ def resolved_containers
56
+ @resolved_containers ||= containers.collect { |container| OSGi::Container.new(container) }
57
+ @resolved_containers
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,104 @@
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 OSGi #:nodoc:
17
+
18
+ # Functions declared on this module are used to select bundles exporting a particular package.
19
+ # Functions must have the signature (package, bundles)
20
+ # where
21
+ # package: the name of the package
22
+ # bundles: an array of bundles
23
+ #
24
+ module PackageResolvingStrategies
25
+
26
+ # Default module function that prompts the user to select the bundle(s)
27
+ # he'd like to select as dependencies.
28
+ #
29
+ def prompt(package, bundles)
30
+ bundle = nil
31
+ while (!bundle)
32
+ puts "This package #{package} is exported by all the bundles present.\n" +
33
+ "Choose a bundle amongst those presented or press A to select them all:\n" + bundles.sort! {|a, b| a.version <=> b.version }.
34
+ collect {|b| "\t#{bundles.index(b) +1}. #{b.name} #{b.version}"}.join("\n")
35
+ number = gets.chomp
36
+ begin
37
+ return bundles if (number == 'A')
38
+ number = number.to_i
39
+ number -= 1
40
+ bundle = bundles[number] if number >= 0 # no negative indexing here.
41
+ rescue Exception => e
42
+ puts "Invalid index"
43
+ #do nothing
44
+ end
45
+ end
46
+ [bundle]
47
+ end
48
+
49
+ # Default module function that selects all the matching bundles to the dependencies.
50
+ # This is the default function.
51
+ #
52
+ def all(package, bundles)
53
+ return bundles
54
+ end
55
+
56
+ module_function :prompt, :all
57
+ end
58
+
59
+ # Functions declared on this module are used to select bundles amongst a list of them,
60
+ # when requiring bundles through the Require-Bundle header.
61
+ # Functions must have the signature (bundles)
62
+ # where
63
+ # bundles: an array of bundles
64
+ #
65
+ module BundleResolvingStrategies
66
+ #
67
+ # Default strategy:
68
+ # the bundle with the highest version number is returned.
69
+ #
70
+ def latest(bundles)
71
+ bundles.sort {|a, b| a.version <=> b.version}.last
72
+ end
73
+
74
+ #
75
+ # The bundle with the lowest version number is returned.
76
+ #
77
+ def oldest(bundles)
78
+ bundles.sort {|a, b| a.version <=> b.version}.first
79
+ end
80
+
81
+ # Default module function that prompts the user to select the bundle
82
+ # he'd like to select as dependencies.
83
+ #
84
+ def prompt(bundles)
85
+ bundle = nil
86
+ while (!bundle)
87
+ puts "Choose a bundle amongst those presented:\n" + bundles.sort! {|a, b| a.version <=> b.version }.
88
+ collect {|b| "\t#{bundles.index(b) +1}. #{b.name} #{b.version}"}.join("\n")
89
+ number = gets.chomp
90
+ begin
91
+ number = number.to_i
92
+ number -= 1
93
+ bundle = bundles[number] if number >= 0 # no negative indexing here.
94
+ rescue Exception => e
95
+ puts "Invalid index"
96
+ #do nothing
97
+ end
98
+ end
99
+ bundle
100
+ end
101
+
102
+ module_function :latest, :oldest, :prompt
103
+ end
104
+ end
@@ -0,0 +1,131 @@
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 OSGi #:nodoc:
17
+
18
+ #
19
+ # A class to represent OSGi versions.
20
+ #
21
+ class Version
22
+
23
+ attr_accessor :major, :minor, :tiny, :qualifier
24
+
25
+ def initialize(string) #:nodoc:
26
+ digits = string.gsub(/\"/, '').split(".")
27
+ @major = digits[0]
28
+ @minor = digits[1]
29
+ @tiny = digits[2]
30
+ @qualifier = digits[3]
31
+ raise "Invalid version: " + self.to_s if @major == ""
32
+ raise "Invalid version: " + self.to_s if @minor == "" && (!@tiny != "" || !@qualifier != "")
33
+ raise "Invalid version: " + self.to_s if @tiny == "" && !@qualifier != ""
34
+ end
35
+
36
+
37
+ def to_s #:nodoc:
38
+ str = [major]
39
+ str << minor if minor
40
+ str << tiny if minor && tiny
41
+ str << qualifier if minor && tiny && qualifier
42
+ str.compact.join(".")
43
+ end
44
+
45
+ def <=>(other) #:nodoc:
46
+ if other.is_a? String
47
+ other = Version.new(other)
48
+ elsif other.nil?
49
+ return 1
50
+ end
51
+
52
+ [:major, :minor, :tiny, :qualifier].each do |digit|
53
+ return 0 if send(digit).nil? or other.send(digit).nil?
54
+
55
+ comparison = send(digit) <=> other.send(digit)
56
+ if comparison != 0
57
+ return comparison
58
+ end
59
+
60
+ end
61
+ return 0
62
+ end
63
+
64
+ def <(other) #:nodoc:
65
+ (self.<=>(other)) == -1
66
+ end
67
+
68
+ def >(other) #:nodoc:
69
+ (self.<=>(other)) == 1
70
+ end
71
+
72
+ def ==(other) #:nodoc:
73
+ (self.<=>(other)) == 0
74
+ end
75
+
76
+ def <=(other) #:nodoc:
77
+ (self.==(other)) || (self.<(other))
78
+ end
79
+
80
+ def >=(other) #:nodoc:
81
+ (self.==(other)) || (self.>(other))
82
+ end
83
+ end
84
+
85
+ class VersionRange #:nodoc:
86
+
87
+ attr_accessor :min, :max, :min_inclusive, :max_inclusive, :max_infinite
88
+
89
+ # Parses a string into a VersionRange.
90
+ # Returns false if the string could not be parsed.
91
+ #
92
+ def self.parse(string, max_infinite = false)
93
+ return string if string.is_a?(VersionRange) || string.is_a?(Version)
94
+ if !string.nil? && (match = string.match /\s*([\[|\(])([0-9|\.]*),([0-9|\.]*)([\]|\)])/)
95
+ range = VersionRange.new
96
+ range.min = Version.new(match[2])
97
+ range.max = Version.new(match[3])
98
+ range.min_inclusive = match[1] == '['
99
+ range.max_inclusive = match[4] == ']'
100
+ range
101
+ elsif (!string.nil? && max_infinite && string.match(/[0-9|\.]*/))
102
+ range = VersionRange.new
103
+ range.min = Version.new(string)
104
+ range.max = nil
105
+ range.min_inclusive = true
106
+ range.max_infinite = true
107
+ range
108
+ else
109
+ false
110
+ end
111
+ end
112
+
113
+ def to_s #:nodoc:
114
+ "#{ min_inclusive ? '[' : '('}#{min},#{max_infinite ? "infinite" : max}#{max_inclusive ? ']' : ')'}"
115
+ end
116
+
117
+ # Returns true if the version is in the range of this VersionRange object.
118
+ # Uses OSGi versioning rules to determine if the version is in range.
119
+ #
120
+ def in_range(version)
121
+ return in_range(version.min) && (version.max_infinite ? true : in_range(version.max)) if version.is_a?(VersionRange)
122
+
123
+ result = min_inclusive ? min <= version : min < version
124
+ if (!max_infinite)
125
+ result &= max_inclusive ? max >= version : max > version
126
+ end
127
+ result
128
+ end
129
+ end
130
+
131
+ end
@@ -0,0 +1,24 @@
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 'buildr4osgi/osgi/version'
17
+ require 'buildr4osgi/osgi/packaging'
18
+ require 'buildr4osgi/osgi/bundle'
19
+ require 'buildr4osgi/osgi/bundle_package'
20
+ require 'buildr4osgi/osgi/container'
21
+ require 'buildr4osgi/osgi/registry'
22
+ require 'buildr4osgi/osgi/resolving_strategies'
23
+ require 'buildr4osgi/osgi/project_extension'
24
+ require 'buildr4osgi/osgi/library_extension'
@@ -0,0 +1,37 @@
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 'buildr4osgi/nature'
17
+ require 'buildr4osgi/osgi'
18
+ require 'buildr4osgi/eclipse'
19
+ require 'buildr4osgi/compile'
20
+
21
+ # Methods defined in Buildr4OSGi are both instance methods (e.g. when included in Project)
22
+ # and class methods when invoked like Buildr4OSGi.project_library(SLF4J, "group", "foo", "1.0.0").
23
+ module Buildr4OSGi ; extend self ; end
24
+ # The Buildfile object (self) has access to all the Buildr4OSGi methods and constants.
25
+ class << self ; include Buildr4OSGi ; end
26
+ class Object #:nodoc:
27
+ Buildr4OSGi.constants.each do |name|
28
+ const = Buildr4OSGi.const_get(name)
29
+ const_set name, const if const.is_a?(Module)
30
+ end
31
+ end
32
+
33
+ # Project has visibility over everything in the Buildr4OSGi namespace.
34
+ # Rename the manifest function first.
35
+ # class Buildr::Project
36
+ # include Buildr4OSGi
37
+ # end