[bugzilla-gnome-org-extensions] Create new extension - ExtensionDependencies



commit 758e25cb04f1dcce1c9f616f8394603333782dba
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Sun Nov 9 21:09:26 2014 +0100

    Create new extension - ExtensionDependencies
    
    This extension checks if runtime dependencies between extensions are
    satisfied. Each extension can specify a sub called gnome_deps in its
    Extension.pm which should return a list of extension names on which it
    depends. The extension name should be without "Bugzilla::Extension::"
    part, for instance:
    
    sub gnome_deps {
        ('GnomeAttachmentStatus',
         'PatchReport');
    }

 ExtensionDependencies/Config.pm                    |   20 ++++++++
 ExtensionDependencies/Extension.pm                 |   27 +++++++++++
 ExtensionDependencies/lib/Util.pm                  |   48 ++++++++++++++++++++
 .../en/default/extensiondependencies/README        |   16 +++++++
 .../template/en/default/hook/README                |    5 ++
 ExtensionDependencies/web/README                   |    7 +++
 TODO                                               |    9 ----
 7 files changed, 123 insertions(+), 9 deletions(-)
---
diff --git a/ExtensionDependencies/Config.pm b/ExtensionDependencies/Config.pm
new file mode 100644
index 0000000..4d55a7d
--- /dev/null
+++ b/ExtensionDependencies/Config.pm
@@ -0,0 +1,20 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Extension::ExtensionDependencies;
+use strict;
+use warnings;
+
+use constant NAME => 'ExtensionDependencies';
+
+use constant REQUIRED_MODULES => [
+];
+
+use constant OPTIONAL_MODULES => [
+];
+
+__PACKAGE__->NAME;
diff --git a/ExtensionDependencies/Extension.pm b/ExtensionDependencies/Extension.pm
new file mode 100644
index 0000000..7709a04
--- /dev/null
+++ b/ExtensionDependencies/Extension.pm
@@ -0,0 +1,27 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Extension::ExtensionDependencies;
+use strict;
+use warnings;
+use base qw(Bugzilla::Extension);
+
+# This code for this is in ./extensions/ExtensionDependencies/lib/Util.pm
+use Bugzilla::Extension::ExtensionDependencies::Util;
+
+our $VERSION = '0.01';
+
+# See the documentation of Bugzilla::Hook ("perldoc Bugzilla::Hook"
+# in the bugzilla directory) for a list of all available hooks.
+sub install_before_final_checks {
+    my ($self, $params) = @_;
+    my $silent = $params->{'silent'};
+
+    check_dependencies($silent);
+}
+
+__PACKAGE__->NAME;
diff --git a/ExtensionDependencies/lib/Util.pm b/ExtensionDependencies/lib/Util.pm
new file mode 100644
index 0000000..04015fa
--- /dev/null
+++ b/ExtensionDependencies/lib/Util.pm
@@ -0,0 +1,48 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Extension::ExtensionDependencies::Util;
+use strict;
+use warnings;
+use base qw(Exporter);
+use Bugzilla;
+our @EXPORT = qw(
+    check_dependencies
+);
+
+# This file can be loaded by your extension via
+# "use Bugzilla::Extension::ExtensionDependencies::Util". You can put functions
+# used by your extension in here. (Make sure you also list them in
+# @EXPORT.)
+
+sub check_dependencies {
+    my ($silent) = @_;
+    my $extensions = Bugzilla->extensions();
+    my %extensions_hash = map { ref($_) => $_ } @{$extensions};
+
+    for my $extension_name (sort keys(%extensions_hash)) {
+        my $extension = $extensions_hash{$extension_name};
+
+        next unless $extension->can('gnome_deps');
+
+        my @deps = map {'Bugzilla::Extension::' . $_} $extension->gnome_deps();
+
+        print "Checking dependencies of $extension_name...\n" unless $silent;
+        for my $dep (@deps) {
+            print "Checking if $dep is available...\n" unless $silent;
+            unless ($extensions_hash{$dep}) {
+                die "$extension_name has unsatisfied dependency on $dep extension - $dep is not available";
+            }
+            print "Checking if $dep is enabled...\n" unless $silent;
+            unless ($extensions_hash{$dep}->enabled()) {
+                die "$extension_name has unsatisfied dependency on $dep extension - $dep is disabled";
+            }
+        }
+    }
+}
+
+1;
diff --git a/ExtensionDependencies/template/en/default/extensiondependencies/README 
b/ExtensionDependencies/template/en/default/extensiondependencies/README
new file mode 100644
index 0000000..cdc6233
--- /dev/null
+++ b/ExtensionDependencies/template/en/default/extensiondependencies/README
@@ -0,0 +1,16 @@
+Normal templates go in this directory. You can load them in your
+code like this:
+
+use Bugzilla::Error;
+my $template = Bugzilla->template;
+$template->process('extensiondependencies/some-template.html.tmpl')
+  or ThrowTemplateError($template->error());
+
+That would be how to load a file called <kbd>some-template.html.tmpl</kbd> that
+was in this directory.
+
+Note that you have to be careful that the full path of your template
+never conflicts with a template that exists in Bugzilla or in 
+another extension, or your template might override that template. That's why
+we created this directory called 'extensiondependencies' for you, so you
+can put your templates in here to help avoid conflicts.
\ No newline at end of file
diff --git a/ExtensionDependencies/template/en/default/hook/README 
b/ExtensionDependencies/template/en/default/hook/README
new file mode 100644
index 0000000..e6c4add
--- /dev/null
+++ b/ExtensionDependencies/template/en/default/hook/README
@@ -0,0 +1,5 @@
+Template hooks go in this directory. Template hooks are called in normal
+Bugzilla templates like [% Hook.process('some-hook') %].
+More information about them can be found in the documentation of 
+Bugzilla::Extension. (Do "perldoc Bugzilla::Extension" from the main
+Bugzilla directory to see that documentation.)
\ No newline at end of file
diff --git a/ExtensionDependencies/web/README b/ExtensionDependencies/web/README
new file mode 100644
index 0000000..2345641
--- /dev/null
+++ b/ExtensionDependencies/web/README
@@ -0,0 +1,7 @@
+Web-accessible files, like JavaScript, CSS, and images go in this
+directory. You can reference them directly in your HTML. For example,
+if you have a file called "style.css" and your extension is called
+"Foo", you would put it in "extensions/Foo/web/style.css", and then
+you could link to it in HTML like:
+
+<link href="extensions/Foo/web/style.css" rel="stylesheet" type="text/css">
\ No newline at end of file
diff --git a/TODO b/TODO
index 3354e24..f076d6b 100644
--- a/TODO
+++ b/TODO
@@ -3,14 +3,5 @@
 - Weekly status page (https://bugzilla.gnome.org/page.cgi?id=weekly-bug-summary.html)
 - Browse page (https://bugzilla.gnome.org/browse.cgi?product=Evolution)
 - Describe user page (https://bugzilla.gnome.org/page.cgi?id=describeuser.html)
-- New extension - ExtensionDeps
-  Create a new extension that will keep the data about dependencies
-  between extensions. For example PatchStatus depends on
-  GnomeAttachmentStatus. In future Browse would depend on DescribeUser
-  and DescribeUser would depend on Browse, Splinter would depend on
-  GnomeAttachmentStatus, WeeklyStatusPage would depend on Browse and
-  DescribeUser and so on.
-  The aim is to have a single place where dependencies are actually
-  checked during checksetup.
 - GnomeAttachmentStatus - shut its migration routine up when running
   checksetup in silent mode


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]