jira4r-uakatt 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ source 'http://uaz-kf-a09.mosaic.arizona.edu/geminabox/'
3
+
4
+ group :development do
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.5.2"
7
+ gem "rspec", ">= 2.5.0"
8
+ gem 'diff-lcs', '= 1.1.2'
9
+ gem "rake", "= 0.8.7"
10
+ end
11
+
12
+ gem "soap4r-uakatt"
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+
2
+ Copyright 2006-2009 Codehaus Foundation
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ 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,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,3 @@
1
+ Codehaus JIRA4R
2
+
3
+ Copyright 2006-2009 The Codehaus Foundation
data/README.textile ADDED
@@ -0,0 +1,3 @@
1
+ h1. jira4r
2
+
3
+ The current gem version of jira4r (0.3.0) is ancient. There is a more up to date version here http://xircles.rubyhaus.org/projects/jira4r so I have just cloned it so I can create my own gem of the source (jira4r-jh). Once a more up to date version of jira4r get's released I will remove this one.
data/README.txt ADDED
@@ -0,0 +1,3 @@
1
+ h1. jira4r
2
+
3
+ The current gem version of jira4r (0.3.0) is ancient. There is a more up to date version here http://xircles.rubyhaus.org/projects/jira4r so I have just cloned it so I can create my own gem of the source (jira4r-jh). Once a more up to date version of jira4r get's released I will remove this one.
data/Rakefile ADDED
@@ -0,0 +1,186 @@
1
+ require 'net/http'
2
+ require 'fileutils'
3
+ require 'rake/clean'
4
+ require 'logger'
5
+
6
+ begin
7
+ require 'rubygems'
8
+ require 'bundler'
9
+ require 'rake/gempackagetask'
10
+ rescue Exception
11
+ nil
12
+ end
13
+
14
+ begin
15
+ Bundler.setup(:default, :development)
16
+ rescue Bundler::BundlerError => e
17
+ $stderr.puts e.message
18
+ $stderr.puts "Run `bundle install` to install missing gems"
19
+ exit e.status_code
20
+ end
21
+ require 'rake'
22
+ require 'jeweler'
23
+
24
+ Jeweler::Tasks.new do |gem|
25
+ gem.name = "jira4r-uakatt"
26
+ gem.homepage = "http://wiki.github.com/uakatt/jira4r"
27
+ gem.license = "Apache"
28
+ gem.summary = %Q{A fork of jira4r-jh-ruby1.9 that requires our soap4r}
29
+ gem.email = ['katt-core@listserv.arizona.edu', 'jamiehollingworth@gmail.com']
30
+ gem.authors = ['Sam Rawlins', 'James Stuart', 'James Hollingworth']
31
+
32
+ gem.add_runtime_dependency 'soap4r-uakatt'
33
+ gem.add_development_dependency 'rspec', '> 1.2.3'
34
+ gem.add_development_dependency 'jeweler'
35
+ gem.add_development_dependency 'bundler'
36
+ end
37
+ Jeweler::RubygemsDotOrgTasks.new
38
+
39
+
40
+ gem 'soap4r-uakatt'
41
+
42
+ require 'wsdl/soap/wsdl2ruby'
43
+
44
+ logger = Logger.new(STDERR)
45
+ logger.level = Logger::INFO
46
+
47
+
48
+ desc "gets the wsdl and generates the classes"
49
+ task :default => [:generate]
50
+
51
+
52
+ desc "gets the wsdl files for JIRA services"
53
+ task :getwsdl do
54
+ versions().each { |version|
55
+ save(getWsdlFileName(version), get_file("jira.codehaus.org", "/rpc/soap/jirasoapservice-v#{version}?wsdl"))
56
+ }
57
+ end
58
+
59
+ task :clean do
60
+ def unl(file)
61
+ File.unlink(file) if File.exist?(file)
62
+ end
63
+ unl("wsdl/jirasoapservice-v2.wsdl")
64
+ unl("lib/jira4r/v2/jiraService.rb")
65
+ unl("lib/jira4r/v2/jiraServiceDriver.rb")
66
+ unl("lib/jira4r/v2/jiraServiceMappingRegistry.rb")
67
+ end
68
+
69
+ desc "generate the wsdl"
70
+ task :generate do
71
+ versions().each { |version|
72
+ wsdl = getWsdlFileName(version)
73
+ basedir = "lib/jira4r/v#{version}"
74
+ mkdir_p basedir
75
+
76
+ if not File.exist?(wsdl)
77
+ raise "WSDL does not exist: #{wsdl}"
78
+ end
79
+ wsdl_url = "file://#{File.expand_path(wsdl)}"
80
+
81
+ # Create the server
82
+ worker = WSDL::SOAP::WSDL2Ruby.new
83
+ worker.logger = logger
84
+ worker.location = wsdl_url
85
+ worker.basedir = basedir
86
+ worker.opt['force'] = true
87
+ worker.opt['classdef'] = "jiraService"
88
+ worker.opt['module_path'] ="Jira4R::V#{version}"
89
+
90
+ worker.opt['mapping_registry'] = true
91
+ #worker.run
92
+
93
+ #Create the driver
94
+ #worker = WSDL::SOAP::WSDL2Ruby.new
95
+ #worker.logger = logger
96
+ #worker.location = wsdl_url
97
+ #worker.basedir = basedir
98
+ #worker.opt['force'] = true
99
+ #worker.opt['module_path'] = "Jira4R::V#{version}"
100
+
101
+ worker.opt['driver'] = "JiraSoapService"
102
+ worker.run
103
+ }
104
+ end
105
+
106
+ def versions
107
+ [ 2 ]
108
+ end
109
+
110
+ def get_file(host, path)
111
+ puts "getting http://#{host}#{path}"
112
+ http = Net::HTTP.new(host)
113
+ http.start { |w| w.get2(path).body }
114
+ end
115
+
116
+ def getWsdlFileName(vName)
117
+ "wsdl/jirasoapservice-v#{vName}.wsdl"
118
+ end
119
+
120
+
121
+ # Saves this document to the specified @var path.
122
+ # doesn't create the file if contains markup for 404 page
123
+ def save( path, content )
124
+ File::open(path, 'w') { | f |
125
+ f.write( content )
126
+ }
127
+ end
128
+
129
+ def fix_soap_files(version)
130
+ fix_require("lib/jira4r/v#{version}/jiraServiceMappingRegistry.rb")
131
+ fix_require("lib/jira4r/v#{version}/JiraSoapServiceDriver.rb")
132
+ end
133
+
134
+ def fix_require(filename)
135
+ content = ""
136
+ File.open(filename) { |io|
137
+ content = io.read()
138
+
139
+ content = fix_content(content, 'jiraService')
140
+ content = fix_content(content, 'jiraServiceMappingRegistry')
141
+ }
142
+
143
+ File.open(filename, "w") { |io|
144
+ io.write(content)
145
+ }
146
+ end
147
+
148
+ def fix_content(content, name)
149
+ return content.gsub("require '#{name}.rb'", "require File.dirname(__FILE__) + '/#{name}.rb'")
150
+ end
151
+
152
+ SPEC_DIR = File.join(File.dirname(__FILE__), 'spec')
153
+ FIXTURE_DIR = File.join(SPEC_DIR, 'fixtures')
154
+ SPECS = "#{SPEC_DIR}/*_spec.rb"
155
+
156
+ begin
157
+ require 'spec/rake/spectask'
158
+
159
+ begin
160
+ require 'rcov/rcovtask'
161
+
162
+ Spec::Rake::SpecTask.new do |t|
163
+ t.libs << SPEC_DIR
164
+ t.pattern = SPECS
165
+ t.rcov = true
166
+ t.rcov_dir = "#{SPEC_DIR}/coverage"
167
+ t.verbose = true
168
+ end
169
+
170
+ desc "Generate and open coverage reports"
171
+ task :rcov do
172
+ system "open #{SPEC_DIR}/coverage/index.html"
173
+ end
174
+ task :rcov => :spec
175
+ rescue LoadError
176
+ ### Enabling these warnings makes every run of rake whiny unless you have these gems.
177
+ # warn ">>> You don't seem to have the rcov gem installed; not adding coverage tasks"
178
+ Spec::Rake::SpecTask.new do |t|
179
+ t.libs << SPEC_DIR
180
+ t.pattern = SPECS
181
+ t.verbose = true
182
+ end
183
+ end
184
+ rescue LoadError
185
+ # warn ">>> You don't seem to have the rspec gem installed; not adding rspec tasks"
186
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.2
Binary file
@@ -0,0 +1,19 @@
1
+ ################################################################################
2
+ # Copyright 2007 Codehaus Foundation #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); #
5
+ # 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, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ ################################################################################
16
+
17
+ #Oh how I hate thee...
18
+ $: << File.dirname(__FILE__) + '/..'
19
+ require 'jira4r/jira_tool.rb'
@@ -0,0 +1,239 @@
1
+ ################################################################################
2
+ # Copyright 2006-2009 Codehaus Foundation
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # 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,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ################################################################################
16
+ require 'logger'
17
+
18
+ #It is the responsibility of the caller to ensure SOAP4R is installed and working correctly
19
+ #require 'rubygems'
20
+ #gem 'soap4r'
21
+
22
+ module Jira4R
23
+
24
+ class JiraTool
25
+ attr_accessor :enhanced
26
+
27
+ # Create a new JiraTool
28
+ #
29
+ # where:
30
+ # version ... the version of the SOAP API you wish to use - currently supported versions [ 2 ]
31
+ # base_url ... the base URL of the JIRA instance - eg. http://confluence.atlassian.com
32
+ def initialize(version, base_url)
33
+ @version = version
34
+ @base_url = base_url
35
+ @logger = Logger.new(STDERR)
36
+ @endpoint_url = "#{@base_url}/rpc/soap/jirasoapservice-v#{version}"
37
+ end
38
+
39
+ #Assign a new logger to the tool. By default a STDERR logger is used.
40
+ def logger=(logger)
41
+ @logger = logger
42
+ end
43
+
44
+ def http_auth(http_username, http_password, http_realm)
45
+ @http_username = http_username
46
+ @http_password = http_password
47
+ @http_realm = http_realm
48
+ end
49
+
50
+ #Retrieve the driver, creating as required.
51
+ def driver()
52
+ if not @driver
53
+ @logger.info( "Connecting driver to #{@endpoint_url}" )
54
+
55
+ require "jira4r/v#{@version}/jiraService.rb"
56
+ require "jira4r/v#{@version}/JiraSoapServiceDriver.rb"
57
+ require "jira4r/v#{@version}/jiraServiceMappingRegistry.rb"
58
+
59
+ service_classname = "Jira4R::V#{@version}::JiraSoapService"
60
+ puts "Service: #{service_classname}"
61
+ service = eval(service_classname)
62
+ @driver = service.send(:new, @endpoint_url)
63
+
64
+ if not ( @http_realm.nil? or @http_username.nil? or @http_password.nil? )
65
+ @driver.options["protocol.http.basic_auth"] << [ @http_realm, @http_username, @http_password ]
66
+ end
67
+ end
68
+ @driver
69
+ end
70
+
71
+ #Assign a wiredump file prefix to the driver.
72
+ def wiredump_file_base=(base)
73
+ driver().wiredump_file_base = base
74
+ end
75
+
76
+
77
+ #Login to the JIRA instance, storing the token for later calls.
78
+ #
79
+ #This is typically the first call that is made on the JiraTool.
80
+ def login(username, password)
81
+ @token = driver().login(username, password)
82
+ end
83
+
84
+ #Clients should avoid using the authentication token directly.
85
+ def token()
86
+ @token
87
+ end
88
+
89
+ #Call a method on the driver, adding in the authentication token previously determined using login()
90
+ def call_driver(method_name, *args)
91
+ @logger.debug("Finding method #{method_name}")
92
+ method = driver().method(method_name)
93
+
94
+ if args.length > 0
95
+ method.call(@token, *args)
96
+ else
97
+ method.call(@token)
98
+ end
99
+ end
100
+
101
+ #Retrieve a project without the associated PermissionScheme.
102
+ #This will be significantly faster for larger Jira installations.
103
+ #See: JRA-10660
104
+ def getProjectNoScheme(key)
105
+ puts "getProjectNoScheme is deprecated. Please call getProjectNoSchemes."
106
+ getProjectNoSchemes(key)
107
+ end
108
+
109
+ def getProjectNoSchemes(key)
110
+ self.getProjectsNoSchemes().find { |project| project.key == key }
111
+ end
112
+
113
+ def getProject(key)
114
+ #Jira > 3.10 has been patched to support this method directly as getProjectByKey
115
+ puts "Using deprecated JIRA4R API call getProject(key); replace with getProjectByKey(key)"
116
+ return getProjectByKey(key)
117
+ end
118
+
119
+ def getProjectByKey( projectKey )
120
+ begin
121
+ return call_driver( "getProjectByKey", projectKey )
122
+ rescue SOAP::FaultError => soap_error
123
+ #XXX surely there is a better way to detect this kind of condition in the JIRA server
124
+ if (soap_error.faultcode.to_s == "soapenv:Server.userException") and
125
+ (soap_error.faultstring.to_s =~ /No project could be found with key '#{projectKey}'/)
126
+ return nil
127
+ else
128
+ raise soap_error
129
+ end
130
+ end
131
+ end
132
+
133
+ def getGroup( groupName )
134
+ begin
135
+ return call_driver( "getGroup", groupName )
136
+ rescue SOAP::FaultError => soap_error
137
+ #XXX surely there is a better way to detect this kind of condition in the JIRA server
138
+ if soap_error.faultcode.to_s == "soapenv:Server.userException" and soap_error.faultstring.to_s == "com.atlassian.jira.rpc.exception.RemoteValidationException: no group found for that groupName: #{groupName}"
139
+ return nil
140
+ else
141
+ raise soap_error
142
+ end
143
+ end
144
+ end
145
+
146
+ def getProjectRoleByName( projectRoleName )
147
+ getProjectRoles.each{ |projectRole|
148
+ return projectRole if projectRole.name == projectRoleName
149
+ }
150
+ end
151
+
152
+ def getPermissionScheme( permissionSchemeName )
153
+ self.getPermissionSchemes().each { |permission_scheme|
154
+ return permission_scheme if permission_scheme.name == permissionSchemeName
155
+ }
156
+ return nil
157
+ end
158
+
159
+ def getNotificationScheme( notificationSchemeName )
160
+ self.getNotificationSchemes().each { |notification_scheme|
161
+ return notification_scheme if notification_scheme.name == notificationSchemeName
162
+ }
163
+ return nil
164
+ end
165
+
166
+ def getPermission( permissionName )
167
+ if not @permissions
168
+ @permissions = self.getAllPermissions()
169
+ end
170
+
171
+ @permissions.each { |permission|
172
+ return permission if permission.name.downcase == permissionName.downcase
173
+ }
174
+
175
+ @logger.warn("No permission #{permissionName} found")
176
+ return nil
177
+ end
178
+
179
+ def findPermission(allowedPermissions, permissionName)
180
+ allowedPermissions.each { |allowedPermission|
181
+ #puts "Checking #{allowedPermission.name} against #{permissionName} "
182
+ return allowedPermission if allowedPermission.name == permissionName
183
+ }
184
+ return nil
185
+ end
186
+
187
+ def findEntityInPermissionMapping(permissionMapping, entityName)
188
+ permissionMapping.remoteEntities.each { |entity|
189
+ return entity if entity.name == entityName
190
+ }
191
+ return nil
192
+ end
193
+
194
+ #Removes entity
195
+ def setPermissions( permissionScheme, allowedPermissions, entity)
196
+ allowedPermissions = [ allowedPermissions ].flatten.compact
197
+ #Remove permissions that are no longer allowed
198
+ permissionScheme.permissionMappings.each { |mapping|
199
+ next unless findEntityInPermissionMapping(mapping, entity.name)
200
+
201
+ allowedPermission = findPermission(allowedPermissions, mapping.permission.name)
202
+ if allowedPermission
203
+ puts "Already has #{allowedPermission.name} in #{permissionScheme.name} for #{entity.name}"
204
+ allowedPermissions.delete(allowedPermission)
205
+ next
206
+ end
207
+
208
+ puts "Deleting #{mapping.permission.name} from #{permissionScheme.name} for #{entity.name}"
209
+ deletePermissionFrom( permissionScheme, mapping.permission, entity)
210
+ }
211
+
212
+ puts allowedPermissions.inspect
213
+ allowedPermissions.each { |allowedPermission|
214
+ puts "Granting #{allowedPermission.name} to #{permissionScheme.name} for #{entity.name}"
215
+ addPermissionTo(permissionScheme, allowedPermission, entity)
216
+ }
217
+ end
218
+
219
+ private
220
+ def fix_args(args)
221
+ args.collect { |arg|
222
+ if arg == nil
223
+ SOAP::SOAPNil.new
224
+ else
225
+ arg
226
+ end
227
+ }
228
+ end
229
+
230
+ def method_missing(method_name, *args)
231
+ args = fix_args(args)
232
+ call_driver(method_name, *args)
233
+ end
234
+
235
+
236
+
237
+ end
238
+
239
+ end