Skip to content

Commit ec462e1

Browse files
Composer 2 support.
1 parent 5d59a82 commit ec462e1

File tree

6 files changed

+40
-28
lines changed

6 files changed

+40
-28
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ git:
1212

1313
before_install:
1414
- phpenv config-rm xdebug.ini
15-
- composer --verbose self-update --1
15+
- composer --verbose self-update --2
1616
- composer --version
1717

1818
install:

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
22
"name": "drupal-composer/drupal-l10n",
3-
"description": "Composer Plugin for downloading Drupal translation files",
43
"type": "composer-plugin",
4+
"description": "Composer Plugin for downloading Drupal translation files",
55
"license": "GPL-2.0-or-later",
66
"require": {
77
"php": ">=5.6",
8-
"composer-plugin-api": "^1.0.0"
8+
"composer-plugin-api": "^2.0"
99
},
10-
"autoload": {
11-
"psr-4": {
12-
"DrupalComposer\\DrupalL10n\\": "src/"
13-
}
10+
"require-dev": {
11+
"composer/composer": "~2.0",
12+
"phpunit/phpunit": "^6"
1413
},
1514
"extra": {
1615
"class": "DrupalComposer\\DrupalL10n\\Plugin"
1716
},
18-
"require-dev": {
19-
"composer/composer": "1.*",
20-
"phpunit/phpunit": "^6"
17+
"autoload": {
18+
"psr-4": {
19+
"DrupalComposer\\DrupalL10n\\": "src/"
20+
}
2121
}
2222
}

src/FileFetcher.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Composer\Downloader\TransportException;
66
use Composer\IO\IOInterface;
77
use Composer\Util\Filesystem;
8-
use Composer\Util\RemoteFilesystem;
8+
use Composer\Util\HttpDownloader;
99

1010
/**
1111
* File fetcher.
@@ -20,11 +20,11 @@ class FileFetcher {
2020
protected $io;
2121

2222
/**
23-
* The remote file system.
23+
* The HTTP downloader.
2424
*
25-
* @var \Composer\Util\RemoteFilesystem
25+
* @var \Composer\Util\HttpDownloader
2626
*/
27-
protected $remoteFilesystem;
27+
protected $httpDownloader;
2828

2929
/**
3030
* An array of options containing the languages and the destination directory.
@@ -59,7 +59,7 @@ class FileFetcher {
5959
*
6060
* @param \Composer\IO\IOInterface $io
6161
* The input output interface.
62-
* @param \Composer\Util\RemoteFilesystem $remote_file_system
62+
* @param \Composer\Util\HttpDownloader $http_downloader
6363
* The remote file system.
6464
* @param array $options
6565
* The composer plugin options.
@@ -68,9 +68,9 @@ class FileFetcher {
6868
* @param bool $progress
6969
* If the command has the progress displayed or not.
7070
*/
71-
public function __construct(IOInterface $io, RemoteFilesystem $remote_file_system, array $options, $core_version, $progress) {
71+
public function __construct(IOInterface $io, HttpDownloader $http_downloader, array $options, $core_version, $progress) {
7272
$this->io = $io;
73-
$this->remoteFilesystem = $remote_file_system;
73+
$this->httpDownloader = $http_downloader;
7474
$this->options = $options;
7575
$this->coreMajorVersion = substr($core_version, 0, 1);
7676
$this->fs = new Filesystem();
@@ -103,7 +103,7 @@ public function fetch(array $drupal_projects, $destination) {
103103
$this->io->write(" - <info>$filename</info> (<comment>$url</comment>): ", FALSE);
104104
}
105105

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

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

src/Handler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Composer\Plugin\CommandEvent;
1414
use Composer\Script\Event;
1515
use Composer\Util\Filesystem;
16-
use Composer\Util\RemoteFilesystem;
16+
use Composer\Util\HttpDownloader;
1717

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

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

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

181181
// Call post-l10n scripts.

src/Plugin.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public function activate(Composer $composer, IOInterface $io) {
3737
$this->handler = new Handler($composer, $io);
3838
}
3939

40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function deactivate(Composer $composer, IOInterface $io) {
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function uninstall(Composer $composer, IOInterface $io) {
50+
}
51+
4052
/**
4153
* {@inheritdoc}
4254
*/

tests/PluginTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function tearDown() {
6767
* Tests a simple composer install and update.
6868
*/
6969
public function testComposerInstallAndUpdate() {
70-
$version = '8.3.0';
70+
$version = '8.9.0';
7171
$translations_directory = $this->tmpDir . DIRECTORY_SEPARATOR . 'translations' . DIRECTORY_SEPARATOR . 'contrib';
7272
$core_directory = $this->tmpDir . DIRECTORY_SEPARATOR . 'core';
7373
$fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $version . '.fr.po';
@@ -94,7 +94,7 @@ public function testComposerInstallAndUpdate() {
9494
$this->assertFileExists($fr_translation_file, 'French translations file should exist.');
9595

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

106106
// Test that the translations for a dev version are not downloaded.
107-
$version = '8.3.x-dev';
107+
$version = '8.9.x-dev';
108108
$fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $version . '.fr.po';
109109
$es_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $version . '.es.po';
110110
$this->assertFileNotExists($fr_translation_file, "French translations file for version: $version should not exist.");
@@ -183,8 +183,8 @@ protected function composerJsonDefaults() {
183183
],
184184
'require' => [
185185
'drupal-composer/drupal-l10n' => $this->tmpReleaseTag,
186-
'composer/installers' => '^1.0.20',
187-
'drupal/core' => '8.3.0',
186+
'composer/installers' => '^1.2',
187+
'drupal/core' => '8.9.0',
188188
],
189189
'extra' => [
190190
'drupal-l10n' => [

0 commit comments

Comments
 (0)