rUtilAnts 0.3.0.20110825 → 1.0.0.20120223

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2009 - 2011 Muriel Salvan (murielsalvan@users.sourceforge.net)
2
+ # Copyright (c) 2009 - 2012 Muriel Salvan (muriel@x-aeon.com)
3
3
  # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
4
  #++
5
5
 
@@ -7,12 +7,12 @@ module RUtilAnts
7
7
 
8
8
  module Platform
9
9
 
10
- class PlatformInfo
10
+ module PlatformInfo
11
11
 
12
12
  # Return the ID of the OS
13
13
  # Applications may adapt their behavior based on it.
14
14
  #
15
- # Return:
15
+ # Return::
16
16
  # * _Integer_: OS ID
17
17
  def os
18
18
  return OS_WINDOWS
@@ -20,7 +20,7 @@ module RUtilAnts
20
20
 
21
21
  # Return the list of directories where we look for executables
22
22
  #
23
- # Return:
23
+ # Return::
24
24
  # * <em>list<String></em>: List of directories
25
25
  def getSystemExePath
26
26
  return ENV['PATH'].split(';')
@@ -28,7 +28,7 @@ module RUtilAnts
28
28
 
29
29
  # Set the list of directories where we look for executables
30
30
  #
31
- # Parameters:
31
+ # Parameters::
32
32
  # * *iNewDirsList* (<em>list<String></em>): List of directories
33
33
  def setSystemExePath(iNewDirsList)
34
34
  ENV['PATH'] = iNewDirsList.join(';')
@@ -37,7 +37,7 @@ module RUtilAnts
37
37
  # Return the list of file extensions that might be discretely happened to executable files.
38
38
  # This is the optional extensions that can be happened when invoked from a terminal.
39
39
  #
40
- # Return:
40
+ # Return::
41
41
  # * <em>list<String></em>: List of extensions (including .)
42
42
  def getDiscreteExeExtensions
43
43
  rExtList = []
@@ -51,7 +51,7 @@ module RUtilAnts
51
51
 
52
52
  # Return the list of directories where we look for libraries
53
53
  #
54
- # Return:
54
+ # Return::
55
55
  # * <em>list<String></em>: List of directories
56
56
  def getSystemLibsPath
57
57
  return ENV['PATH'].split(';')
@@ -59,7 +59,7 @@ module RUtilAnts
59
59
 
60
60
  # Set the list of directories where we look for libraries
61
61
  #
62
- # Parameters:
62
+ # Parameters::
63
63
  # * *iNewDirsList* (<em>list<String></em>): List of directories
64
64
  def setSystemLibsPath(iNewDirsList)
65
65
  ENV['PATH'] = iNewDirsList.join(';')
@@ -67,7 +67,7 @@ module RUtilAnts
67
67
 
68
68
  # This method sends a message (platform dependent) to the user, without the use of wxruby
69
69
  #
70
- # Parameters:
70
+ # Parameters::
71
71
  # * *iMsg* (_String_): The message to display
72
72
  def sendMsg(iMsg)
73
73
  # iMsg must not be longer than 255 characters
@@ -82,10 +82,10 @@ module RUtilAnts
82
82
  # Execute a Shell command.
83
83
  # Do not wait for its termination.
84
84
  #
85
- # Parameters:
85
+ # Parameters::
86
86
  # * *iCmd* (_String_): The command to execute
87
87
  # * *iInTerminal* (_Boolean_): Do we execute this command in a separate terminal ?
88
- # Return:
88
+ # Return::
89
89
  # * _Exception_: Error, or nil if success
90
90
  def execShellCmdNoWait(iCmd, iInTerminal)
91
91
  rException = nil
@@ -107,9 +107,9 @@ module RUtilAnts
107
107
 
108
108
  # Execute a given URL to be launched in a browser
109
109
  #
110
- # Parameters:
110
+ # Parameters::
111
111
  # * *iURL* (_String_): The URL to launch
112
- # Return:
112
+ # Return::
113
113
  # * _String_: Error message, or nil if success
114
114
  def launchURL(iURL)
115
115
  rError = nil
@@ -127,21 +127,62 @@ module RUtilAnts
127
127
 
128
128
  # Get file extensions specifics to executable files
129
129
  #
130
- # Return:
130
+ # Return::
131
131
  # * <em>list<String></em>: List of extensions (including . character). It can be empty.
132
132
  def getExecutableExtensions
133
- # TODO: Use PATHEXT environment variable if possible
134
- return [ '.exe', '.com', '.bat' ]
133
+ rLstExt = [ '.exe', '.com', '.bat' ]
134
+
135
+ # Use PATHEXT environment variable if possible
136
+ if (ENV['PATHEXT'] != nil)
137
+ rLstExt.concat(ENV['PATHEXT'].split(';').map { |iExt| iExt.downcase })
138
+ rLstExt.uniq!
139
+ end
140
+
141
+ return rLstExt
135
142
  end
136
143
 
137
144
  # Get prohibited characters from file names
138
145
  #
139
- # Return:
146
+ # Return::
140
147
  # * _String_: String of prohibited characters in file names
141
148
  def getProhibitedFileNamesCharacters
142
149
  return '\\/:*?"<>|'
143
150
  end
144
151
 
152
+ # Create a shortcut (ln -s on Cygwin/Unix systems, a .lnk file on Windows systems)
153
+ #
154
+ # Parameters::
155
+ # * *iSrc* (_String_): The source file
156
+ # * *iDst* (_String_): The destination file
157
+ def createShortcut(iSrc, iDst)
158
+ require 'win32/shortcut'
159
+ Win32::Shortcut.new(getShortcutFileName(iDst)) do |oShortcut|
160
+ oShortcut.path = File.expand_path(iSrc)
161
+ end
162
+ end
163
+
164
+ # Get the name of a real file name, pointed by a shortcut.
165
+ # On Windows systems, it will be the target of the lnk file.
166
+ #
167
+ # Parameters::
168
+ # * *iShortcutName* (_String_): Name of the shortcut (same name used by createShortcut). Don't use OS specific extensions in this name (no .lnk).
169
+ # Return::
170
+ # * _String_: The real file name pointed by this shortcut
171
+ def followShortcut(iShortcutName)
172
+ require 'win32/shortcut'
173
+ return Win32::Shortcut.open(getShortcutFileName(iShortcutName)).path
174
+ end
175
+
176
+ # Get the real file name of a shortcut
177
+ #
178
+ # Parameters::
179
+ # * *iDst* (_String_): The destination file that will host the shortcut
180
+ # Return::
181
+ # * _String_: The real shortcut file name
182
+ def getShortcutFileName(iDst)
183
+ return "#{iDst}.lnk"
184
+ end
185
+
145
186
  end
146
187
 
147
188
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2009 - 2011 Muriel Salvan (murielsalvan@users.sourceforge.net)
2
+ # Copyright (c) 2009 - 2012 Muriel Salvan (muriel@x-aeon.com)
3
3
  # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
4
  #++
5
5
 
@@ -7,12 +7,12 @@ module RUtilAnts
7
7
 
8
8
  module Platform
9
9
 
10
- class PlatformInfo
10
+ module PlatformInfo
11
11
 
12
12
  # Return the ID of the OS
13
13
  # Applications may adapt their behavior based on it.
14
14
  #
15
- # Return:
15
+ # Return::
16
16
  # * _Integer_: OS ID
17
17
  def os
18
18
  return OS_LINUX
@@ -20,7 +20,7 @@ module RUtilAnts
20
20
 
21
21
  # Return the list of directories where we look for executables
22
22
  #
23
- # Return:
23
+ # Return::
24
24
  # * <em>list<String></em>: List of directories
25
25
  def getSystemExePath
26
26
  return ENV['PATH'].split(':')
@@ -28,7 +28,7 @@ module RUtilAnts
28
28
 
29
29
  # Set the list of directories where we look for executables
30
30
  #
31
- # Parameters:
31
+ # Parameters::
32
32
  # * *iNewDirsList* (<em>list<String></em>): List of directories
33
33
  def setSystemExePath(iNewDirsList)
34
34
  ENV['PATH'] = iNewDirsList.join(':')
@@ -37,7 +37,7 @@ module RUtilAnts
37
37
  # Return the list of file extensions that might be discretely happened to executable files.
38
38
  # This is the optional extensions that can be happened when invoked from a terminal.
39
39
  #
40
- # Return:
40
+ # Return::
41
41
  # * <em>list<String></em>: List of extensions (including .)
42
42
  def getDiscreteExeExtensions
43
43
  return []
@@ -45,7 +45,7 @@ module RUtilAnts
45
45
 
46
46
  # Return the list of directories where we look for libraries
47
47
  #
48
- # Return:
48
+ # Return::
49
49
  # * <em>list<String></em>: List of directories
50
50
  def getSystemLibsPath
51
51
  rList = ENV['PATH'].split(':')
@@ -59,7 +59,7 @@ module RUtilAnts
59
59
 
60
60
  # Set the list of directories where we look for libraries
61
61
  #
62
- # Parameters:
62
+ # Parameters::
63
63
  # * *iNewDirsList* (<em>list<String></em>): List of directories
64
64
  def setSystemLibsPath(iNewDirsList)
65
65
  ENV['LD_LIBRARY_PATH'] = iNewDirsList.join(':')
@@ -67,7 +67,7 @@ module RUtilAnts
67
67
 
68
68
  # This method sends a message (platform dependent) to the user, without the use of wxruby
69
69
  #
70
- # Parameters:
70
+ # Parameters::
71
71
  # * *iMsg* (_String_): The message to display
72
72
  def sendMsg(iMsg)
73
73
  # TODO: Handle case of xmessage not installed
@@ -84,10 +84,10 @@ module RUtilAnts
84
84
  # Execute a Shell command.
85
85
  # Do not wait for its termination.
86
86
  #
87
- # Parameters:
87
+ # Parameters::
88
88
  # * *iCmd* (_String_): The command to execute
89
89
  # * *iInTerminal* (_Boolean_): Do we execute this command in a separate terminal ?
90
- # Return:
90
+ # Return::
91
91
  # * _Exception_: Error, or nil if success
92
92
  def execShellCmdNoWait(iCmd, iInTerminal)
93
93
  rException = nil
@@ -110,9 +110,9 @@ module RUtilAnts
110
110
 
111
111
  # Execute a given URL to be launched in a browser
112
112
  #
113
- # Parameters:
113
+ # Parameters::
114
114
  # * *iURL* (_String_): The URL to launch
115
- # Return:
115
+ # Return::
116
116
  # * _String_: Error message, or nil if success
117
117
  def launchURL(iURL)
118
118
  rError = nil
@@ -128,7 +128,7 @@ module RUtilAnts
128
128
 
129
129
  # Get file extensions specifics to executable files
130
130
  #
131
- # Return:
131
+ # Return::
132
132
  # * <em>list<String></em>: List of extensions (including . character). It can be empty.
133
133
  def getExecutableExtensions
134
134
  return []
@@ -136,12 +136,43 @@ module RUtilAnts
136
136
 
137
137
  # Get prohibited characters from file names
138
138
  #
139
- # Return:
139
+ # Return::
140
140
  # * _String_: String of prohibited characters in file names
141
141
  def getProhibitedFileNamesCharacters
142
142
  return '/'
143
143
  end
144
144
 
145
+ # Create a shortcut (ln -s on Cygwin/Unix systems, a .lnk file on Windows systems)
146
+ #
147
+ # Parameters::
148
+ # * *iSrc* (_String_): The source file
149
+ # * *iDst* (_String_): The destination file
150
+ def createShortcut(iSrc, iDst)
151
+ require 'fileutils'
152
+ FileUtils::ln_s(iSrc, iDst)
153
+ end
154
+
155
+ # Get the name of a real file name, pointed by a shortcut.
156
+ # On Windows systems, it will be the target of the lnk file.
157
+ #
158
+ # Parameters::
159
+ # * *iShortcutName* (_String_): Name of the shortcut (same name used by createShortcut). Don't use OS specific extensions in this name (no .lnk).
160
+ # Return::
161
+ # * _String_: The real file name pointed by this shortcut
162
+ def followShortcut(iShortcutName)
163
+ return File.readlink(iShortcutName)
164
+ end
165
+
166
+ # Get the real file name of a shortcut
167
+ #
168
+ # Parameters::
169
+ # * *iDst* (_String_): The destination file that will host the shortcut
170
+ # Return::
171
+ # * _String_: The real shortcut file name
172
+ def getShortcutFileName(iDst)
173
+ return iDst
174
+ end
175
+
145
176
  end
146
177
 
147
178
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2009 - 2011 Muriel Salvan (murielsalvan@users.sourceforge.net)
2
+ # Copyright (c) 2009 - 2012 Muriel Salvan (muriel@x-aeon.com)
3
3
  # Licensed under the terms specified in LICENSE file. No warranty is provided.
4
4
  #++
5
5
 
@@ -53,11 +53,10 @@ module RUtilAnts
53
53
  class PluginDependenciesUnresolvedError < RuntimeError
54
54
  end
55
55
 
56
- # Main class storing info about plugins
57
- class PluginsManager
56
+ module PluginsInterface
58
57
 
59
58
  # Constructor
60
- def initialize
59
+ def init_plugins
61
60
  # Map of plugins, per category
62
61
  # map< String, map< String, map< Symbol, Object > > >
63
62
  @Plugins = {}
@@ -65,14 +64,14 @@ module RUtilAnts
65
64
 
66
65
  # Register a new plugin
67
66
  #
68
- # Parameters:
67
+ # Parameters::
69
68
  # * *iCategoryName* (_String_): Category this plugin belongs to
70
69
  # * *iPluginName* (_String_): Plugin name
71
70
  # * *iFileName* (_String_): File name containing the plugin (can be nil)
72
71
  # * *iDesc* (<em>map<Symbol,Object></em>): Plugin's description (can be nil)
73
72
  # * *iClassName* (_String_): Name of the plugin class
74
73
  # * *iInitCodeBlock* (_Proc_): Code block to call when initializing the real instance (can be nil)
75
- def registerNewPlugin(iCategoryName, iPluginName, iFileName, iDesc, iClassName, iInitCodeBlock)
74
+ def register_new_plugin(iCategoryName, iPluginName, iFileName, iDesc, iClassName, iInitCodeBlock)
76
75
  # Complete the description with some metadata
77
76
  if (@Plugins[iCategoryName] == nil)
78
77
  @Plugins[iCategoryName] = {}
@@ -95,13 +94,13 @@ module RUtilAnts
95
94
 
96
95
  # Parse plugins from a given directory
97
96
  #
98
- # Parameters:
97
+ # Parameters::
99
98
  # * *iCategory* (_Object_): Category those plugins will belong to
100
99
  # * *iDir* (_String_): Directory to parse for plugins
101
100
  # * *iBaseClassNames* (_String_): The base class name of plugins to be instantiated
102
101
  # * *iInitCodeBlock* (_CodeBlock_): Code to be executed first time the plugin will be instantiated (can be ommitted):
103
- # ** *ioPlugin* (_Object_): Plugin instance
104
- def parsePluginsFromDir(iCategory, iDir, iBaseClassNames, &iInitCodeBlock)
102
+ # * *ioPlugin* (_Object_): Plugin instance
103
+ def parse_plugins_from_dir(iCategory, iDir, iBaseClassNames, &iInitCodeBlock)
105
104
  # Gather descriptions
106
105
  # map< String, map >
107
106
  lDescriptions = {}
@@ -115,11 +114,11 @@ module RUtilAnts
115
114
  if (lDesc.is_a?(Hash))
116
115
  lDescriptions[lPluginName] = lDesc
117
116
  else
118
- logBug "Plugin description #{iFileName} is incorrect. The file should just describe a simple hash map."
117
+ log_bug "Plugin description #{iFileName} is incorrect. The file should just describe a simple hash map."
119
118
  end
120
119
  end
121
120
  rescue Exception
122
- logExc $!, "Error while loading file #{iFileName}. Ignoring this description."
121
+ log_exc $!, "Error while loading file #{iFileName}. Ignoring this description."
123
122
  end
124
123
  end
125
124
  # Now, parse the plugins themselves
@@ -132,7 +131,7 @@ module RUtilAnts
132
131
  if (@Plugins[iCategory][lPluginName] == nil)
133
132
  # Check if we have a description
134
133
  lDesc = lDescriptions[lPluginName]
135
- registerNewPlugin(
134
+ register_new_plugin(
136
135
  iCategory,
137
136
  lPluginName,
138
137
  iFileName,
@@ -141,7 +140,7 @@ module RUtilAnts
141
140
  iInitCodeBlock
142
141
  )
143
142
  else
144
- logErr "Plugin named #{lPluginName} in category #{iCategory} already exists. Please name it differently. Ignoring it from #{iFileName}."
143
+ log_warn "Plugin named #{lPluginName} in category #{iCategory} already exists. Please name it differently. Ignoring it from #{iFileName}."
145
144
  end
146
145
  end
147
146
  end
@@ -149,17 +148,17 @@ module RUtilAnts
149
148
  # Get the named plugin instance.
150
149
  # Uses RDI if given in parameters or if Main RDI Installer defined to resolve Plugins' dependencies.
151
150
  #
152
- # Parameters:
151
+ # Parameters::
153
152
  # * *iCategory* (_Object_): Category those plugins will belong to
154
153
  # * *iPluginName* (_String_): Plugin name
155
154
  # * *iParameters* (<em>map<Symbol,Object></em>): Additional parameters:
156
- # ** *OnlyIfExtDepsResolved* (_Boolean_): Do we return the plugin only if there is no need to install external dependencies ? [optional = false]
157
- # ** *RDIInstaller* (<em>RDI::Installer</em>): The RDI installer if available, or nil otherwise [optional = nil]
158
- # ** *RDIContextModifiers* (<em>map<String,list<[String,Object]>></em>): The map of context modifiers to be filled by the RDI installer if specified, or nil if ignored [optional = nil]
159
- # Return:
155
+ # * *OnlyIfExtDepsResolved* (_Boolean_): Do we return the plugin only if there is no need to install external dependencies ? [optional = false]
156
+ # * *RDIInstaller* (<em>RDI::Installer</em>): The RDI installer if available, or nil otherwise [optional = nil]
157
+ # * *RDIContextModifiers* (<em>map<String,list< [String,Object] >></em>): The map of context modifiers to be filled by the RDI installer if specified, or nil if ignored [optional = nil]
158
+ # Return::
160
159
  # * _Object_: The corresponding plugin, or nil in case of failure
161
160
  # * _Exception_: The error, or nil in case of success
162
- def getPluginInstance(iCategory, iPluginName, iParameters = {})
161
+ def get_plugin_instance(iCategory, iPluginName, iParameters = {})
163
162
  rPlugin = nil
164
163
  rError = nil
165
164
 
@@ -185,14 +184,14 @@ module RUtilAnts
185
184
  # If it is not given as parameter, try getting the singleton
186
185
  if ((lRDIInstaller == nil) and
187
186
  (defined?(RDI::Installer) != nil))
188
- lRDIInstaller = RDI::Installer.getMainInstance
187
+ lRDIInstaller = RDI::Installer.get_main_instance
189
188
  end
190
189
  if (lRDIInstaller != nil)
191
190
  if (lOnlyIfExtDepsResolved)
192
191
  # Test that each dependency is accessible
193
192
  lSuccess = true
194
193
  lDesc[:Dependencies].each do |iDepDesc|
195
- lSuccess = lRDIInstaller.testDependency(iDepDesc)
194
+ lSuccess = lRDIInstaller.test_dependency(iDepDesc)
196
195
  if (!lSuccess)
197
196
  # It is useless to continue
198
197
  break
@@ -200,7 +199,7 @@ module RUtilAnts
200
199
  end
201
200
  else
202
201
  # Load other dependencies
203
- lError, lContextModifiers, lIgnored, lUnresolved = lRDIInstaller.ensureDependencies(lDesc[:Dependencies])
202
+ lError, lContextModifiers, lIgnored, lUnresolved = lRDIInstaller.ensure_dependencies(lDesc[:Dependencies])
204
203
  if (lRDIContextModifiers != nil)
205
204
  lRDIContextModifiers.merge!(lContextModifiers)
206
205
  end
@@ -224,7 +223,7 @@ module RUtilAnts
224
223
  # Load other plugins
225
224
  lDesc[:PluginsDependencies].each do |iPluginInfo|
226
225
  iPluginCategory, iPluginName = iPluginInfo
227
- lPlugin, lError = getPluginInstance(iPluginCategory, iPluginName, iParameters)
226
+ lPlugin, lError = get_plugin_instance(iPluginCategory, iPluginName, iParameters)
228
227
  lSuccess = (lError == nil)
229
228
  if (!lSuccess)
230
229
  # Don't try further
@@ -267,20 +266,20 @@ module RUtilAnts
267
266
 
268
267
  # Get the named plugin description
269
268
  #
270
- # Parameters:
269
+ # Parameters::
271
270
  # * *iCategory* (_Object_): Category those plugins will belong to
272
271
  # * *iPluginName* (_String_): Plugin name
273
- # Return:
274
- # * <em>map<Symbol,Object></em>: The corresponding description, or nil in case of failure
275
- def getPluginDescription(iCategory, iPluginName)
272
+ # Return::
273
+ # * <em>map<Symbol,Object></em>: The corresponding description
274
+ def get_plugin_description(iCategory, iPluginName)
276
275
  rDesc = nil
277
276
 
278
277
  if (@Plugins[iCategory] == nil)
279
- logErr "Unknown plugins category #{iCategory}."
278
+ raise UnknownCategoryError.new("Unknown plugins category #{iCategory}.")
280
279
  else
281
280
  rDesc = @Plugins[iCategory][iPluginName]
282
281
  if (rDesc == nil)
283
- logErr "Unknown plugin #{iPluginName} in category #{iCategory}."
282
+ raise UnknownPluginError.new("Unknown plugin #{iPluginName} in category #{iCategory}.")
284
283
  end
285
284
  end
286
285
 
@@ -290,17 +289,17 @@ module RUtilAnts
290
289
  # Give access to a plugin.
291
290
  # An exception is thrown if the plugin does not exist.
292
291
  #
293
- # Parameters:
292
+ # Parameters::
294
293
  # * *iCategoryName* (_String_): Category of the plugin to access
295
294
  # * *iPluginName* (_String_): Name of the plugin to access
296
295
  # * *iParameters* (<em>map<Symbol,Object></em>): Additional parameters:
297
- # ** *OnlyIfExtDepsResolved* (_Boolean_): Do we return the plugin only if there is no need to install external dependencies ? [optional = false]
298
- # ** *RDIInstaller* (<em>RDI::Installer</em>): The RDI installer if available, or nil otherwise [optional = nil]
299
- # ** *RDIContextModifiers* (<em>map<String,list<[String,Object]>></em>): The map of context modifiers to be filled by the RDI installer if specified, or nil if ignored [optional = nil]
296
+ # * *OnlyIfExtDepsResolved* (_Boolean_): Do we return the plugin only if there is no need to install external dependencies ? [optional = false]
297
+ # * *RDIInstaller* (<em>RDI::Installer</em>): The RDI installer if available, or nil otherwise [optional = nil]
298
+ # * *RDIContextModifiers* (<em>map<String,list< [String,Object] >></em>): The map of context modifiers to be filled by the RDI installer if specified, or nil if ignored [optional = nil]
300
299
  # * *CodeBlock*: The code called when the plugin is found:
301
- # ** *ioPlugin* (_Object_): The corresponding plugin
302
- def accessPlugin(iCategoryName, iPluginName, iParameters = {})
303
- lPlugin, lError = getPluginInstance(iCategoryName, iPluginName, iParameters)
300
+ # * *ioPlugin* (_Object_): The corresponding plugin
301
+ def access_plugin(iCategoryName, iPluginName, iParameters = {})
302
+ lPlugin, lError = get_plugin_instance(iCategoryName, iPluginName, iParameters)
304
303
  if (lPlugin == nil)
305
304
  raise lError
306
305
  else
@@ -315,13 +314,13 @@ module RUtilAnts
315
314
 
316
315
  # Get the list of plugin names of a given category
317
316
  #
318
- # Parameters:
317
+ # Parameters::
319
318
  # * *iCategoryName* (_String_): The category for which we want the plugin names list
320
319
  # * *iParameters* (<em>map<Symbol,Object></em>): Additional parameters:
321
- # ** *IncludeDisabled* (_Boolean_): Do we include disabled plugins ? [optional = false]
322
- # Return:
320
+ # * *IncludeDisabled* (_Boolean_): Do we include disabled plugins ? [optional = false]
321
+ # Return::
323
322
  # * <em>list<String></em>: The list of plugin names in this category
324
- def getPluginNames(iCategoryName, iParameters = {})
323
+ def get_plugins_names(iCategoryName, iParameters = {})
325
324
  rPlugins = []
326
325
 
327
326
  lIncludeDisabled = iParameters[:IncludeDisabled]
@@ -342,13 +341,13 @@ module RUtilAnts
342
341
 
343
342
  # Get the map of plugins descriptions, indexed with plugin names
344
343
  #
345
- # Parameters:
344
+ # Parameters::
346
345
  # * *iCategoryName* (_String_): The category for which we want the plugin names list
347
346
  # * *iParameters* (<em>map<Symbol,Object></em>): Additional parameters:
348
- # ** *IncludeDisabled* (_Boolean_): Do we include disabled plugins ? [optional = false]
349
- # Return:
347
+ # * *IncludeDisabled* (_Boolean_): Do we include disabled plugins ? [optional = false]
348
+ # Return::
350
349
  # * <em>map<String,map<Symbol,Object>></em>: The map of plugin descriptions per plugin name
351
- def getPluginsDescriptions(iCategoryName, iParameters = {})
350
+ def get_plugins_descriptions(iCategoryName, iParameters = {})
352
351
  rPlugins = {}
353
352
 
354
353
  lIncludeDisabled = iParameters[:IncludeDisabled]
@@ -372,107 +371,23 @@ module RUtilAnts
372
371
 
373
372
  end
374
373
 
375
- # Initialize a plugins singleton
376
- def self.initializePlugins
377
- $rUtilAnts_Plugins_Manager = PluginsManager.new
378
- Object.module_eval('include RUtilAnts::Plugins')
379
- end
380
-
381
- # Register a new plugin
382
- #
383
- # Parameters:
384
- # * *iCategoryName* (_String_): Category this plugin belongs to
385
- # * *iPluginName* (_String_): Plugin name
386
- # * *iFileName* (_String_): File name containing the plugin (can be nil)
387
- # * *iDesc* (<em>map<Symbol,Object></em>): Plugin's description (can be nil)
388
- # * *iClassName* (_String_): Name of the plugin class
389
- # * *iInitCodeBlock* (_Proc_): Code block to call when initializing the real instance (can be nil)
390
- def registerNewPlugin(iCategoryName, iPluginName, iFileName, iDesc, iClassName, iInitCodeBlock)
391
- $rUtilAnts_Plugins_Manager.registerNewPlugin(iCategoryName, iPluginName, iFileName, iDesc, iClassName, iInitCodeBlock)
392
- end
393
-
394
- # Parse plugins from a given directory
395
- #
396
- # Parameters:
397
- # * *iCategory* (_Object_): Category those plugins will belong to
398
- # * *iDir* (_String_): Directory to parse for plugins
399
- # * *iBaseClassNames* (_String_): The base class name of plugins to be instantiated
400
- def parsePluginsFromDir(iCategory, iDir, iBaseClassNames)
401
- $rUtilAnts_Plugins_Manager.parsePluginsFromDir(iCategory, iDir, iBaseClassNames)
402
- end
403
-
404
- # Get the named plugin instance
405
- #
406
- # Parameters:
407
- # * *iCategory* (_Object_): Category those plugins will belong to
408
- # * *iPluginName* (_String_): Plugin name
409
- # * *iParameters* (<em>map<Symbol,Object></em>): Additional parameters:
410
- # ** *OnlyIfExtDepsResolved* (_Boolean_): Do we return the plugin only if there is no need to install external dependencies ? [optional = false]
411
- # ** *RDIInstaller* (<em>RDI::Installer</em>): The RDI installer if available, or nil otherwise [optional = nil]
412
- # ** *RDIContextModifiers* (<em>map<String,list<[String,Object]>></em>): The map of context modifiers to be filled by the RDI installer if specified, or nil if ignored [optional = nil]
413
- # Return:
414
- # * _Object_: The corresponding plugin, or nil in case of failure
415
- # * _Exception_: The error, or nil in case of success
416
- def getPluginInstance(iCategory, iPluginName, iParameters = {})
417
- return $rUtilAnts_Plugins_Manager.getPluginInstance(iCategory, iPluginName, iParameters)
418
- end
374
+ # Main class storing info about plugins
375
+ class PluginsManager
419
376
 
420
- # Get the named plugin description
421
- #
422
- # Parameters:
423
- # * *iCategory* (_Object_): Category those plugins will belong to
424
- # * *iPluginName* (_String_): Plugin name
425
- # Return:
426
- # * <em>map<Symbol,Object></em>: The corresponding description, or nil in case of failure
427
- def getPluginDescription(iCategory, iPluginName)
428
- return $rUtilAnts_Plugins_Manager.getPluginDescription(iCategory, iPluginName)
429
- end
377
+ include PluginsInterface
430
378
 
431
- # Give access to a plugin.
432
- # An exception is thrown if the plugin does not exist.
433
- #
434
- # Parameters:
435
- # * *iCategoryName* (_String_): Category of the plugin to access
436
- # * *iPluginName* (_String_): Name of the plugin to access
437
- # * *iParameters* (<em>map<Symbol,Object></em>): Additional parameters:
438
- # ** *OnlyIfExtDepsResolved* (_Boolean_): Do we return the plugin only if there is no need to install external dependencies ? [optional = false]
439
- # ** *RDIInstaller* (<em>RDI::Installer</em>): The RDI installer if available, or nil otherwise [optional = nil]
440
- # ** *RDIContextModifiers* (<em>map<String,list<[String,Object]>></em>): The map of context modifiers to be filled by the RDI installer if specified, or nil if ignored [optional = nil]
441
- # * *CodeBlock*: The code called when the plugin is found:
442
- # ** *ioPlugin* (_Object_): The corresponding plugin
443
- def accessPlugin(iCategoryName, iPluginName, iParameters = {})
444
- $rUtilAnts_Plugins_Manager.accessPlugin(iCategoryName, iPluginName, iParameters) do |ioPlugin|
445
- yield(ioPlugin)
379
+ # Constructor
380
+ def initialize
381
+ init_plugins
446
382
  end
447
- end
448
383
 
449
- # Clear the registered plugins
450
- def clearPlugins
451
- $rUtilAnts_Plugins_Manager.clearPlugins
452
384
  end
453
385
 
454
- # Get the list of plugin names of a given category
455
- #
456
- # Parameters:
457
- # * *iCategoryName* (_String_): The category for which we want the plugin names list
458
- # * *iParameters* (<em>map<Symbol,Object></em>): Additional parameters:
459
- # ** *IncludeDisabled* (_Boolean_): Do we include disabled plugins ? [optional = false]
460
- # Return:
461
- # * <em>list<String></em>: The list of plugin names in this category
462
- def getPluginNames(iCategoryName, iParameters = {})
463
- return $rUtilAnts_Plugins_Manager.getPluginNames(iCategoryName, iParameters)
464
- end
465
-
466
- # Get the map of plugins descriptions, indexed with plugin names
467
- #
468
- # Parameters:
469
- # * *iCategoryName* (_String_): The category for which we want the plugin names list
470
- # * *iParameters* (<em>map<Symbol,Object></em>): Additional parameters:
471
- # ** *IncludeDisabled* (_Boolean_): Do we include disabled plugins ? [optional = false]
472
- # Return:
473
- # * <em>map<String,map<Symbol,Object>></em>: The map of plugin descriptions per plugin name
474
- def getPluginsDescriptions(iCategoryName, iParameters = {})
475
- return $rUtilAnts_Plugins_Manager.getPluginsDescriptions(iCategoryName, iParameters)
386
+ # Initialize a plugins singleton
387
+ def self.install_plugins_on_object
388
+ require 'rUtilAnts/SingletonProxy'
389
+ RUtilAnts::make_singleton_proxy(RUtilAnts::Plugins::PluginsInterface, Object)
390
+ init_plugins
476
391
  end
477
392
 
478
393
  end