]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 415278: Make the WebService's plugin discovery method more extendable
authormozilla%colinogilvie.co.uk <>
Mon, 19 May 2008 23:38:23 +0000 (23:38 +0000)
committermozilla%colinogilvie.co.uk <>
Mon, 19 May 2008 23:38:23 +0000 (23:38 +0000)
Patch by: Colin Ogilvie <colin.ogilvie@gmail.com>; r=mkanat; a=LpSolit

Bugzilla/Hook.pm
Bugzilla/WebService/Bugzilla.pm
contrib/bz_webservice_demo.pl
extensions/example/info.pl [new file with mode: 0644]

index 7c47b3f3fb723114c48d45644d6ae861774a5e15..0cf566db10289271c60c6923077d8a19eaddabfc 100644 (file)
@@ -69,7 +69,7 @@ sub enabled_plugins {
         next if -e "$extension/disabled";
         # Allow extensions to load their own libraries.
         local @INC = ("$extension/lib", @INC);
-        $enabled{$extname} = do("$extension/version.pl");
+        $enabled{$extname} = do("$extension/info.pl");
         ThrowCodeError('extension_invalid',
                 { errstr => $@, name => 'version',
                   extension => $extension }) if $@;
@@ -125,9 +125,12 @@ hook to do anything, you have to modify these variables.
 
 =head2 Versioning Extensions
 
-Every extension must have a file in its root called F<version.pl>.
-This file should return a version number when called with C<do>.
-This represents the current version of this extension.
+Every extension must have a file in its root called F<info.pl>.
+This file must return a hash when called with C<do>.
+The hash must contain a 'version' key with the current version of the
+extension. Extension authors can also add any extra infomration to this hash if
+required, by adding a new key beginning with x_ which will not be used the
+core Bugzilla code. 
 
 =head1 SUBROUTINES
 
index dde9cfd4b8baf251e8d22f5828ccbf84cddd7738..7b58af254029a0db122823e5e44f1d010a859221 100755 (executable)
@@ -36,12 +36,16 @@ sub version {
     return { version => type('string')->value(BUGZILLA_VERSION) };
 }
 
-sub plugins {
-    my $plugins = Bugzilla::Hook::enabled_plugins();
-    foreach my $name (keys %$plugins) {
-        $plugins->{$name} = type('string')->value($plugins->{$name});
+sub extensions {
+    my $extensions = Bugzilla::Hook::enabled_plugins();
+    foreach my $name (keys %$extensions) {
+        my $info = $extensions->{$name};
+        foreach my $data (keys %$info)
+        {
+            $extensions->{$name}->{$data} = type('string')->value($info->{$data});
+        }
     }
-    return { plugins => $plugins };
+    return { extensions => $extensions };
 }
 
 sub timezone {
@@ -89,22 +93,23 @@ string.
 
 =back
 
-=item C<plugins> B<EXPERIMENTAL>
+=item C<extensions> B<EXPERIMENTAL>
 
 =over
 
 =item B<Description>
 
-Gets information about the plugins that are currently installed and enabled
+Gets information about the extensions that are currently installed and enabled
 in this Bugzilla.
 
 =item B<Params> (none)
 
 =item B<Returns>
 
-A hash with a single item, C<plugins>. This points to a hash. I<That> hash
-contains the names of plugins as keys, and the versions of the plugin as
-values.
+A hash with a single item, C<extesions>. This points to a hash. I<That> hash
+contains the names of extensions as keys, and information about the extension
+as values. One of the values that must be returned is the 'version' of the
+extension
 
 =back
 
index a5e6af9f95694a5d0c4863167bcb27c9251cba64..32c8561a0dd0d34ffaa76d066abb7643d08f06a5 100755 (executable)
@@ -54,6 +54,7 @@ my $legal_field_values;
 my $add_comment;
 my $private;
 my $work_time;
+my $fetch_extension_info = 0;
 
 GetOptions('help|h|?'       => \$help,
            'uri=s'          => \$Bugzilla_uri,
@@ -66,7 +67,8 @@ GetOptions('help|h|?'       => \$help,
            'field:s'        => \$legal_field_values,
            'comment:s'      => \$add_comment,
            'private:i'      => \$private,
-           'worktime:f'     => \$work_time
+           'worktime:f'     => \$work_time,
+           'extension_info'    => \$fetch_extension_info
           ) or pod2usage({'-verbose' => 0, '-exitval' => 1});
 
 =head1 OPTIONS
@@ -133,6 +135,10 @@ An optional non-zero value to specify B<--comment> as private.
 
 An optional double precision number specifying the work time for B<--comment>.
 
+=item --extension_info
+
+If specified on the command line, the script returns the information about the
+extensions that are installed.
 
 =back
 
@@ -193,6 +199,25 @@ $soapresult = $proxy->call('Bugzilla.timezone');
 _die_on_fault($soapresult);
 print 'Bugzilla\'s timezone is ' . $soapresult->result()->{timezone} . ".\n";
 
+=head2 Getting Extension Information
+
+Returns all the information any extensions have decided to provide to the webservice.
+
+=cut
+
+if ($fetch_extension_info) {
+    $soapresult = $proxy->call('Bugzilla.extensions');
+    _die_on_fault($soapresult);
+    my $extensions = $soapresult->result()->{extensions};
+    foreach my $extensionname (keys(%$extensions)) {
+        print "Extensionn '$extensionname' information\n";
+        my $extension = $extensions->{$extensionname};
+        foreach my $data (keys(%$extension)) {
+            print '  ' . $data . ' => ' . $extension->{$data} . "\n";
+        }
+    }
+}
+
 =head2 Logging In and Out
 
 =head3 Using Bugzilla's Environment Authentication
diff --git a/extensions/example/info.pl b/extensions/example/info.pl
new file mode 100644 (file)
index 0000000..b4620ee
--- /dev/null
@@ -0,0 +1,41 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Example WebService Plugin
+#
+# The Initial Developer of the Original Code is Everything Solved, Inc.
+# Portions created by Everything Solved, Inc. are Copyright (C) 2007
+# Everything Solved, Inc. All Rights Reserved.
+#
+# Contributor(s): Max Kanat-Alexander <mkanat@bugzilla.org>
+#                 Colin Ogilvie <colin.ogilvie@gmail.com>
+
+# This script does some code to return a hash about the Extension.
+# You are required to return a hash containing the Extension version
+# You can optionaally add any other values to the hash too, as long as
+# they begin with an x_
+#
+# Eg:
+# {
+#   'version' => '0.1', # required
+#   'x_name'  => 'Example Extension'
+# }
+
+use strict;
+no warnings qw(void); # Avoid "useless use of a constant in void context"
+use Bugzilla::Constants;
+
+{
+       'version' => BUGZILLA_VERSION,
+       'x_blah'  => 'Hello....',
+
+};