Florianschmidtwelzow has uploaded a new change for review.
https://gerrit.wikimedia.org/r/261633
Change subject: Maintenance: convertExtensionToRegistration: Detect, if
composer autoloader is needed
......................................................................
Maintenance: convertExtensionToRegistration: Detect, if composer autoloader is
needed
If an extension specifies a require section in it's composer.json, which
contains
some dependencies, we can assume, that this extension needs to load the composer
autoloader. The maintenance sscript convertExtensionToRegistration.php will now
check, if the extension has such a composer.josn and if so, addds the
load_composer_autoloader
property in extension.json, which will try to load the autoloader of composer
is it is present.
Nitpick: Also add a check for existence of a require section in ComposerJson
library
(ComposerJson::getRequiredDependencies()).
Change-Id: Icdbc37abc44e642afee2aab4c0e9298d3471124d
---
M includes/libs/composer/ComposerJson.php
M maintenance/convertExtensionToRegistration.php
2 files changed, 21 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/33/261633/1
diff --git a/includes/libs/composer/ComposerJson.php
b/includes/libs/composer/ComposerJson.php
index 796acb5..bb55ac6 100644
--- a/includes/libs/composer/ComposerJson.php
+++ b/includes/libs/composer/ComposerJson.php
@@ -27,9 +27,11 @@
*/
public function getRequiredDependencies() {
$deps = array();
- foreach ( $this->contents['require'] as $package => $version ) {
- if ( $package !== "php" && strpos( $package, 'ext-' )
!== 0 ) {
- $deps[$package] = self::normalizeVersion(
$version );
+ if ( isset( $this->contents['require'] ) ) {
+ foreach ( $this->contents['require'] as $package =>
$version ) {
+ if ( $package !== "php" && strpos( $package,
'ext-' ) !== 0 ) {
+ $deps[$package] =
self::normalizeVersion( $version );
+ }
}
}
diff --git a/maintenance/convertExtensionToRegistration.php
b/maintenance/convertExtensionToRegistration.php
index 608605c..6675f39 100644
--- a/maintenance/convertExtensionToRegistration.php
+++ b/maintenance/convertExtensionToRegistration.php
@@ -116,6 +116,12 @@
}
}
+ // check, if the extension requires composer libraries
+ if ( $this->needsComposerAutoloader( dirname( $this->getArg( 0
) ) ) ) {
+ // set the load composer autoloader automatically
property
+ $this->json['load_composer_autoloader'] = true;
+ }
+
// Move some keys to the top
$out = array();
foreach ( $this->promote as $key ) {
@@ -246,6 +252,16 @@
$this->json['ResourceFileModulePaths'] = $defaults;
}
}
+
+ protected function needsComposerAutoloader( $path ) {
+ // assume, that the composer.json file is in the root of the
extension path
+ $composerJson = new ComposerJson( $path . '/composer.json' );
+ // check, if there are some dependencies in the require section
+ if ( $composerJson->getRequiredDependencies() ) {
+ return true;
+ }
+ return false;
+ }
}
$maintClass = 'ConvertExtensionToRegistration';
--
To view, visit https://gerrit.wikimedia.org/r/261633
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icdbc37abc44e642afee2aab4c0e9298d3471124d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits