capistrano-karaf 1.4.1 → 1.4.2

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.
Files changed (2) hide show
  1. data/lib/capistrano-karaf/install.rb +83 -17
  2. metadata +1 -1
@@ -4,17 +4,25 @@ require 'capistrano-karaf/core'
4
4
  require 'capistrano-karaf/extended'
5
5
  require 'capistrano-karaf/semver'
6
6
 
7
- module Capistrano_Karaf
7
+ require 'net/http'
8
+ require 'rexml/document'
9
+
10
+ module Install
8
11
  include Semantic_Versions
9
12
 
10
13
  # Upgrade a list of projects in karaf
11
14
  #
12
- # projects - a list of hashes containing:
15
+ # projects - a list of hashes containing either:
13
16
  # - :feature_url - the string containing the feature url
14
17
  # - :feature - the string containing the feature name to upgrade
15
18
  # - :version - the string containing the version
16
- # - :condition - specifies when to upgrade the feature, one of [ :lt, :eq, :gt ( the default ) ]
17
- #
19
+ # - :condition - specifies when to upgrade the feature, one of [ :lt, :eq, :gt ( the default ) ]
20
+ # or:
21
+ # - :groupId - the string containing the groupId of the repository
22
+ # - :repository - the string containing the name of the feature repository
23
+ # - :feature - the string containing the name of the feature
24
+ # - :version - the string containing the version or :latest
25
+ # - :condition - specifies when to upgrade the feature, one of [ :lt, :eq, :gt ( the default ) ]
18
26
  # Examples
19
27
  # upgrade([{:feature_url => "mvn:repository/featurea/xml/features/1.1.0",
20
28
  # :feature => "featurea",
@@ -25,6 +33,12 @@ module Capistrano_Karaf
25
33
  # :feature => "featureb",
26
34
  # :version => "1.2.0",
27
35
  # :condition => gt
36
+ # },
37
+ # {:groupId => "repository",
38
+ # :repository => "featureb",
39
+ # :feature => "featureb",
40
+ # :version => :latest
41
+ # }
28
42
  # }])
29
43
  # # => nil
30
44
  #
@@ -33,28 +47,80 @@ module Capistrano_Karaf
33
47
  features = list_features()
34
48
  projects.each do |project|
35
49
  project = {:condition => :gt}.merge(project)
36
-
50
+
37
51
  install_new_feature = true
38
52
  installed_features = find_installed_with_name(features, project[:feature])
39
53
 
40
- p = method(project[:condition])
41
- installed_features.each do |f|
42
- if p.call(f["version"], project[:version])
43
- feature_uninstall("#{project[:feature]}/#{f['version']}")
44
- else
45
- install_new_feature = false
46
- end
47
- end
48
-
49
- if install_new_feature
50
- add_url(project[:feature_url])
51
- feature_install(project[:feature])
54
+ if project.keys.include? :groupId then
55
+ fh = create_feature_hash(project[:groupId], project[:repository], project[:feature], project[:version], project[:condition])
56
+ upgrade_feature(installed_features, fh)
57
+ else
58
+ upgrade_feature(installed_features, project)
52
59
  end
53
60
  end
54
61
  end
55
62
 
63
+ # Extract the latest version from a maven-metadata file
64
+ #
65
+ # Parameters
66
+ # - xml - A string containing the xml file
67
+ #
68
+ # Example
69
+ # extract_latest_version(xml)
70
+ # # returns "2.19.1-SNAPSHOT"
71
+ #
72
+ # Returns a string containing the version
73
+ def extract_latest_version (xml)
74
+ doc = REXML::Document.new(xml)
75
+ version = REXML::XPath.first(doc, "/metadata/versioning/latest").text
76
+ end
77
+
56
78
  private
79
+ def latest_snapshot_version (groupId, artifactId)
80
+ groupId1 = groupId.split('.').join('/')
81
+ url = "http://nexus.colo.elex.be:8081/nexus/content/groups/public-snapshots/#{groupId1}/#{artifactId}/maven-metadata.xml"
82
+ uri = URI(url)
83
+ maven_metadata = Net::HTTP.get(uri)
84
+ end
85
+
57
86
  def find_installed_with_name (features, name)
58
87
  features.select {|f| f["name"] == name and f["status"] == "installed"}
59
88
  end
89
+
90
+ def upgrade_feature(installed_features, feature)
91
+ install_new_feature = true
92
+ p = method(feature[:condition])
93
+
94
+ installed_features.each do |f|
95
+ if p.call(f["version"], feature[:version])
96
+ feature_uninstall("#{feature[:feature]}/#{f['version']}")
97
+ else
98
+ install_new_feature = false
99
+ end
100
+ end
101
+
102
+ if install_new_feature
103
+ puts "Installing feature #{feature}"
104
+ add_url(feature[:feature_url])
105
+ feature_install(feature[:feature])
106
+ end
107
+ end
108
+
109
+ def create_feature_hash(groupId, repository, feature, version, condition)
110
+ version1 = nil
111
+ if version == :latest then
112
+ version1 = extract_latest_version(latest_snapshot_version(groupId, repository))
113
+ else
114
+ version1 = version
115
+ end
116
+
117
+ groupIdUrl = groupId.sub(/\./, "/")
118
+ featureUrl = "mvn:#{groupId.sub(/\./, "/")}/#{repository}/#{version1}/xml/features"
119
+
120
+ {:feature_url => featureUrl,
121
+ :feature => feature,
122
+ :version => version1,
123
+ :condition => condition
124
+ }
125
+ end
60
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-karaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: