Skip to content

Commit

Permalink
Composer 2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentTorregrosa committed Oct 31, 2020
1 parent 5d59a82 commit ec462e1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ git:

before_install:
- phpenv config-rm xdebug.ini
- composer --verbose self-update --1
- composer --verbose self-update --2
- composer --version

install:
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "drupal-composer/drupal-l10n",
"description": "Composer Plugin for downloading Drupal translation files",
"type": "composer-plugin",
"description": "Composer Plugin for downloading Drupal translation files",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=5.6",
"composer-plugin-api": "^1.0.0"
"composer-plugin-api": "^2.0"
},
"autoload": {
"psr-4": {
"DrupalComposer\\DrupalL10n\\": "src/"
}
"require-dev": {
"composer/composer": "~2.0",
"phpunit/phpunit": "^6"
},
"extra": {
"class": "DrupalComposer\\DrupalL10n\\Plugin"
},
"require-dev": {
"composer/composer": "1.*",
"phpunit/phpunit": "^6"
"autoload": {
"psr-4": {
"DrupalComposer\\DrupalL10n\\": "src/"
}
}
}
20 changes: 10 additions & 10 deletions src/FileFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Composer\Downloader\TransportException;
use Composer\IO\IOInterface;
use Composer\Util\Filesystem;
use Composer\Util\RemoteFilesystem;
use Composer\Util\HttpDownloader;

/**
* File fetcher.
Expand All @@ -20,11 +20,11 @@ class FileFetcher {
protected $io;

/**
* The remote file system.
* The HTTP downloader.
*
* @var \Composer\Util\RemoteFilesystem
* @var \Composer\Util\HttpDownloader
*/
protected $remoteFilesystem;
protected $httpDownloader;

/**
* An array of options containing the languages and the destination directory.
Expand Down Expand Up @@ -59,7 +59,7 @@ class FileFetcher {
*
* @param \Composer\IO\IOInterface $io
* The input output interface.
* @param \Composer\Util\RemoteFilesystem $remote_file_system
* @param \Composer\Util\HttpDownloader $http_downloader
* The remote file system.
* @param array $options
* The composer plugin options.
Expand All @@ -68,9 +68,9 @@ class FileFetcher {
* @param bool $progress
* If the command has the progress displayed or not.
*/
public function __construct(IOInterface $io, RemoteFilesystem $remote_file_system, array $options, $core_version, $progress) {
public function __construct(IOInterface $io, HttpDownloader $http_downloader, array $options, $core_version, $progress) {
$this->io = $io;
$this->remoteFilesystem = $remote_file_system;
$this->httpDownloader = $http_downloader;
$this->options = $options;
$this->coreMajorVersion = substr($core_version, 0, 1);
$this->fs = new Filesystem();
Expand Down Expand Up @@ -103,7 +103,7 @@ public function fetch(array $drupal_projects, $destination) {
$this->io->write(" - <info>$filename</info> (<comment>$url</comment>): ", FALSE);
}

$this->remoteFilesystem->copy($url, $url, $destination . '/' . $filename);
$this->httpDownloader->copy($url, $destination . '/' . $filename);

if ($this->progress) {
// Used to put a new line because the remote file system does not
Expand Down Expand Up @@ -179,10 +179,10 @@ protected function getFilename($package_name, $drupal_version, $drupal_project_n
protected function getUrl($package_name, $drupal_project_name, $filename) {
// Special case for Drupal core.
if (in_array($package_name, ['drupal/core', 'drupal/drupal'])) {
return 'http://ftp.drupal.org/files/translations/' . $this->coreMajorVersion . '.x/drupal/' . $filename;
return 'https://ftp.drupal.org/files/translations/' . $this->coreMajorVersion . '.x/drupal/' . $filename;
}
else {
return 'http://ftp.drupal.org/files/translations/' . $this->coreMajorVersion . '.x/' . $drupal_project_name . '/' . $filename;
return 'https://ftp.drupal.org/files/translations/' . $this->coreMajorVersion . '.x/' . $drupal_project_name . '/' . $filename;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Composer\Plugin\CommandEvent;
use Composer\Script\Event;
use Composer\Util\Filesystem;
use Composer\Util\RemoteFilesystem;
use Composer\Util\HttpDownloader;

/**
* Handler that do the actual stuff.
Expand Down Expand Up @@ -173,9 +173,9 @@ public function downloadLocalization($dev = TRUE, array $packages = []) {
// Collect options.
$options = $this->getOptions();

$remoteFs = new RemoteFilesystem($this->io);
$httpDownloader = new HttpDownloader($this->io, $this->composer->getConfig());

$fetcher = new FileFetcher($this->io, $remoteFs, $options, $core_version, $this->progress);
$fetcher = new FileFetcher($this->io, $httpDownloader, $options, $core_version, $this->progress);
$fetcher->fetch($drupal_projects, $webroot . '/' . $options['destination']);

// Call post-l10n scripts.
Expand Down
12 changes: 12 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public function activate(Composer $composer, IOInterface $io) {
$this->handler = new Handler($composer, $io);
}

/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io) {
}

/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io) {
}

/**
* {@inheritdoc}
*/
Expand Down
10 changes: 5 additions & 5 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function tearDown() {
* Tests a simple composer install and update.
*/
public function testComposerInstallAndUpdate() {
$version = '8.3.0';
$version = '8.9.0';
$translations_directory = $this->tmpDir . DIRECTORY_SEPARATOR . 'translations' . DIRECTORY_SEPARATOR . 'contrib';
$core_directory = $this->tmpDir . DIRECTORY_SEPARATOR . 'core';
$fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $version . '.fr.po';
Expand All @@ -94,7 +94,7 @@ public function testComposerInstallAndUpdate() {
$this->assertFileExists($fr_translation_file, 'French translations file should exist.');

// Test downloading a new version of the translations.
$version = '8.3.1';
$version = '8.9.7';
$fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $version . '.fr.po';
$es_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $version . '.es.po';
$this->assertFileNotExists($fr_translation_file, "French translations file for version: $version should not exist.");
Expand All @@ -104,7 +104,7 @@ public function testComposerInstallAndUpdate() {
$this->assertFileExists($es_translation_file, "Spanish translations file for version: $version should exist.");

// Test that the translations for a dev version are not downloaded.
$version = '8.3.x-dev';
$version = '8.9.x-dev';
$fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $version . '.fr.po';
$es_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $version . '.es.po';
$this->assertFileNotExists($fr_translation_file, "French translations file for version: $version should not exist.");
Expand Down Expand Up @@ -183,8 +183,8 @@ protected function composerJsonDefaults() {
],
'require' => [
'drupal-composer/drupal-l10n' => $this->tmpReleaseTag,
'composer/installers' => '^1.0.20',
'drupal/core' => '8.3.0',
'composer/installers' => '^1.2',
'drupal/core' => '8.9.0',
],
'extra' => [
'drupal-l10n' => [
Expand Down

0 comments on commit ec462e1

Please sign in to comment.